-
Notifications
You must be signed in to change notification settings - Fork 146
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DE-1343 Create func NewMessage and NewMIMEMessage (#335)
- Loading branch information
Showing
10 changed files
with
113 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,12 +39,12 @@ func main() { | |
recipient := "[email protected]" | ||
|
||
// The message object allows you to add attachments and Bcc recipients | ||
message := mg.NewMessage(sender, subject, body, recipient) | ||
message := mailgun.NewMessage(sender, subject, body, recipient) | ||
|
||
ctx, cancel := context.WithTimeout(context.Background(), time.Second*10) | ||
defer cancel() | ||
|
||
// Send the message with a 10 second timeout | ||
// Send the message with a 10-second timeout | ||
resp, id, err := mg.Send(ctx, message) | ||
|
||
if err != nil { | ||
|
@@ -281,7 +281,7 @@ func main() { | |
subject := "HTML email!" | ||
recipient := "[email protected]" | ||
|
||
message := mg.NewMessage(sender, subject, "", recipient) | ||
message := mailgun.NewMessage(sender, subject, "", recipient) | ||
body := ` | ||
<html> | ||
<body> | ||
|
@@ -292,7 +292,7 @@ func main() { | |
</html> | ||
` | ||
|
||
message.SetHtml(body) | ||
message.SetHTML(body) | ||
|
||
ctx, cancel := context.WithTimeout(context.Background(), time.Second*10) | ||
defer cancel() | ||
|
@@ -342,7 +342,7 @@ func main() { | |
recipient := "[email protected]" | ||
|
||
// The message object allows you to add attachments and Bcc recipients | ||
message := mg.NewMessage(sender, subject, body, recipient) | ||
message := mailgun.NewMessage(sender, subject, body, recipient) | ||
message.SetTemplate("passwordReset") | ||
err := message.AddTemplateVariable("passwordResetLink", "some link to your site unique to your user") | ||
if err != nil { | ||
|
@@ -352,9 +352,8 @@ func main() { | |
ctx, cancel := context.WithTimeout(context.Background(), time.Second*10) | ||
defer cancel() | ||
|
||
// Send the message with a 10 second timeout | ||
// Send the message with a 10-second timeout | ||
resp, id, err := mg.Send(ctx, message) | ||
|
||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,10 +3,11 @@ package examples | |
import ( | ||
"context" | ||
"fmt" | ||
"github.com/mailgun/mailgun-go/v4" | ||
"github.com/mailgun/mailgun-go/v4/events" | ||
"os" | ||
"time" | ||
|
||
"github.com/mailgun/mailgun-go/v4" | ||
"github.com/mailgun/mailgun-go/v4/events" | ||
) | ||
|
||
func AddBounce(domain, apiKey string) error { | ||
|
@@ -696,15 +697,15 @@ func ResendMessage(domain, apiKey string) (string, string, error) { | |
|
||
func SendComplexMessage(domain, apiKey string) (string, error) { | ||
mg := mailgun.NewMailgun(domain, apiKey) | ||
m := mg.NewMessage( | ||
m := mailgun.NewMessage( | ||
"Excited User <YOU@YOUR_DOMAIN_NAME>", | ||
"Hello", | ||
"Testing some Mailgun awesomeness!", | ||
"[email protected]", | ||
) | ||
m.AddCC("[email protected]") | ||
m.AddBCC("[email protected]") | ||
m.SetHtml("<html>HTML version of the body</html>") | ||
m.SetHTML("<html>HTML version of the body</html>") | ||
m.AddAttachment("files/test.jpg") | ||
m.AddAttachment("files/test.txt") | ||
|
||
|
@@ -717,7 +718,7 @@ func SendComplexMessage(domain, apiKey string) (string, error) { | |
|
||
func SendWithConnectionOptions(domain, apiKey string) (string, error) { | ||
mg := mailgun.NewMailgun(domain, apiKey) | ||
m := mg.NewMessage( | ||
m := mailgun.NewMessage( | ||
"Excited User <YOU@YOUR_DOMAIN_NAME>", | ||
"Hello", | ||
"Testing some Mailgun awesomeness!", | ||
|
@@ -736,15 +737,15 @@ func SendWithConnectionOptions(domain, apiKey string) (string, error) { | |
|
||
func SendInlineImage(domain, apiKey string) (string, error) { | ||
mg := mailgun.NewMailgun(domain, apiKey) | ||
m := mg.NewMessage( | ||
m := mailgun.NewMessage( | ||
"Excited User <YOU@YOUR_DOMAIN_NAME>", | ||
"Hello", | ||
"Testing some Mailgun awesomeness!", | ||
"[email protected]", | ||
) | ||
m.AddCC("[email protected]") | ||
m.AddBCC("[email protected]") | ||
m.SetHtml(`<html>Inline image here: <img alt="image" src="cid:test.jpg"/></html>`) | ||
m.SetHTML(`<html>Inline image here: <img alt="image" src="cid:test.jpg"/></html>`) | ||
m.AddInline("files/test.jpg") | ||
|
||
ctx, cancel := context.WithTimeout(context.Background(), time.Second*30) | ||
|
@@ -756,7 +757,7 @@ func SendInlineImage(domain, apiKey string) (string, error) { | |
|
||
func SendMessageNoTracking(domain, apiKey string) (string, error) { | ||
mg := mailgun.NewMailgun(domain, apiKey) | ||
m := mg.NewMessage( | ||
m := mailgun.NewMessage( | ||
"Excited User <YOU@YOUR_DOMAIN_NAME>", | ||
"Hello", | ||
"Testing some Mailgun awesomeness!", | ||
|
@@ -778,7 +779,7 @@ func SendMimeMessage(domain, apiKey string) (string, error) { | |
return "", err | ||
} | ||
|
||
m := mg.NewMIMEMessage(mimeMsgReader, "[email protected]") | ||
m := mailgun.NewMIMEMessage(mimeMsgReader, "[email protected]") | ||
|
||
ctx, cancel := context.WithTimeout(context.Background(), time.Second*30) | ||
defer cancel() | ||
|
@@ -789,7 +790,7 @@ func SendMimeMessage(domain, apiKey string) (string, error) { | |
|
||
func SendScheduledMessage(domain, apiKey string) (string, error) { | ||
mg := mailgun.NewMailgun(domain, apiKey) | ||
m := mg.NewMessage( | ||
m := mailgun.NewMessage( | ||
"Excited User <YOU@YOUR_DOMAIN_NAME>", | ||
"Hello", | ||
"Testing some Mailgun awesomeness!", | ||
|
@@ -806,7 +807,7 @@ func SendScheduledMessage(domain, apiKey string) (string, error) { | |
|
||
func SendSimpleMessage(domain, apiKey string) (string, error) { | ||
mg := mailgun.NewMailgun(domain, apiKey) | ||
m := mg.NewMessage( | ||
m := mailgun.NewMessage( | ||
"Excited User <mailgun@YOUR_DOMAIN_NAME>", | ||
"Hello", | ||
"Testing some Mailgun awesomeness!", | ||
|
@@ -822,7 +823,7 @@ func SendSimpleMessage(domain, apiKey string) (string, error) { | |
|
||
func SendTaggedMessage(domain, apiKey string) (string, error) { | ||
mg := mailgun.NewMailgun(domain, apiKey) | ||
m := mg.NewMessage( | ||
m := mailgun.NewMessage( | ||
"Excited User <YOU@YOUR_DOMAIN_NAME>", | ||
"Hello", | ||
"Testing some Mailgun awesomeness!", | ||
|
@@ -843,12 +844,12 @@ func SendTaggedMessage(domain, apiKey string) (string, error) { | |
|
||
func SendTemplateMessage(domain, apiKey string) (string, error) { | ||
mg := mailgun.NewMailgun(domain, apiKey) | ||
m := mg.NewMessage( | ||
m := mailgun.NewMessage( | ||
"Excited User <YOU@YOUR_DOMAIN_NAME>", | ||
"Hey %recipient.first%", | ||
"If you wish to unsubscribe, click http://mailgun/unsubscribe/%recipient.id%", | ||
) // IMPORTANT: No To:-field recipients! | ||
|
||
// Set template to be applied to this message. | ||
m.SetTemplate("my-template") | ||
|
||
|
@@ -937,7 +938,7 @@ func SendMessageWithTemplate(domain, apiKey string) error { | |
time.Sleep(time.Second * 1) | ||
|
||
// Create a new message with template | ||
m := mg.NewMessage("Excited User <[email protected]>", "Template example", "") | ||
m := mailgun.NewMessage("Excited User <[email protected]>", "Template example", "") | ||
m.SetTemplate("my-template") | ||
|
||
// Add recipients | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ import ( | |
"context" | ||
"encoding/json" | ||
"fmt" | ||
"io/ioutil" | ||
"io" | ||
"log" | ||
"net/http" | ||
"os" | ||
|
@@ -80,7 +80,7 @@ func ExampleMailgunImpl_Send_constructed() { | |
ctx, cancel := context.WithTimeout(context.Background(), time.Second*10) | ||
defer cancel() | ||
|
||
m := mg.NewMessage( | ||
m := mailgun.NewMessage( | ||
"Excited User <[email protected]>", | ||
"Hello World", | ||
"Testing some Mailgun Awesomeness!", | ||
|
@@ -89,7 +89,7 @@ func ExampleMailgunImpl_Send_constructed() { | |
) | ||
m.SetTracking(true) | ||
m.SetDeliveryTime(time.Now().Add(24 * time.Hour)) | ||
m.SetHtml("<html><body><h1>Testing some Mailgun Awesomeness!!</h1></body></html>") | ||
m.SetHTML("<html><body><h1>Testing some Mailgun Awesomeness!!</h1></body></html>") | ||
_, id, err := mg.Send(ctx, m) | ||
if err != nil { | ||
log.Fatal(err) | ||
|
@@ -112,7 +112,7 @@ Testing some Mailgun MIME awesomeness! | |
defer cancel() | ||
|
||
mg := mailgun.NewMailgun("example.com", "my_api_key") | ||
m := mg.NewMIMEMessage(ioutil.NopCloser(strings.NewReader(exampleMime)), "[email protected]") | ||
m := mailgun.NewMIMEMessage(io.NopCloser(strings.NewReader(exampleMime)), "[email protected]") | ||
_, id, err := mg.Send(ctx, m) | ||
if err != nil { | ||
log.Fatal(err) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.