Skip to content

Commit

Permalink
DE-1388 (mg *MailgunImpl) Send should accept interface, not struct (#368
Browse files Browse the repository at this point in the history
  • Loading branch information
vtopc authored Dec 15, 2024
1 parent 34b51e0 commit a2a4cfd
Show file tree
Hide file tree
Showing 12 changed files with 156 additions and 213 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func main() {
recipient := "[email protected]"

// The message object allows you to add attachments and Bcc recipients
message := mailgun.NewMessage(sender, subject, body, recipient)
message := mailgun.NewMessage(yourDomain, sender, subject, body, recipient)

ctx, cancel := context.WithTimeout(context.Background(), time.Second*10)
defer cancel()
Expand Down Expand Up @@ -290,7 +290,7 @@ func main() {
subject := "HTML email!"
recipient := "[email protected]"

message := mailgun.NewMessage(sender, subject, "", recipient)
message := mailgun.NewMessage(yourDomain, sender, subject, "", recipient)
body := `
<html>
<body>
Expand Down Expand Up @@ -351,7 +351,7 @@ func main() {
recipient := "[email protected]"

// The message object allows you to add attachments and Bcc recipients
message := mailgun.NewMessage(sender, subject, body, recipient)
message := mailgun.NewMessage(yourDomain, sender, subject, body, recipient)
message.SetTemplate("passwordReset")
err := message.AddTemplateVariable("passwordResetLink", "some link to your site unique to your user")
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion attachments_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func TestMultipleAttachments(t *testing.T) {

var ctx = context.Background()

m := mailgun.NewMessage("root@"+testDomain, "Subject", "Text Body", "attachment@"+testDomain)
m := mailgun.NewMessage(testDomain, "root@"+testDomain, "Subject", "Text Body", "attachment@"+testDomain)

// Add 2 attachments
m.AddAttachment(createAttachment(t))
Expand Down
2 changes: 1 addition & 1 deletion events_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func TestEventPoller(t *testing.T) {
}()

// Send an email
m := mailgun.NewMessage("root@"+testDomain, "Subject", "Text Body", "user@"+testDomain)
m := mailgun.NewMessage(testDomain, "root@"+testDomain, "Subject", "Text Body", "user@"+testDomain)
msg, id, err := mg.Send(ctx, m)
require.NoError(t, err)

Expand Down
6 changes: 4 additions & 2 deletions examples/examples.go
Original file line number Diff line number Diff line change
Expand Up @@ -779,7 +779,7 @@ func SendMimeMessage(domain, apiKey string) (string, error) {
return "", err
}

m := mailgun.NewMIMEMessage(mimeMsgReader, "[email protected]")
m := mailgun.NewMIMEMessage(domain, mimeMsgReader, "[email protected]")

ctx, cancel := context.WithTimeout(context.Background(), time.Second*30)
defer cancel()
Expand Down Expand Up @@ -824,6 +824,7 @@ func SendSimpleMessage(domain, apiKey string) (string, error) {
func SendTaggedMessage(domain, apiKey string) (string, error) {
mg := mailgun.NewMailgun(domain, apiKey)
m := mailgun.NewMessage(
domain,
"Excited User <YOU@YOUR_DOMAIN_NAME>",
"Hello",
"Testing some Mailgun awesomeness!",
Expand All @@ -845,6 +846,7 @@ func SendTaggedMessage(domain, apiKey string) (string, error) {
func SendTemplateMessage(domain, apiKey string) (string, error) {
mg := mailgun.NewMailgun(domain, apiKey)
m := mailgun.NewMessage(
domain,
"Excited User <YOU@YOUR_DOMAIN_NAME>",
"Hey %recipient.first%",
"If you wish to unsubscribe, click http://mailgun/unsubscribe/%recipient.id%",
Expand Down Expand Up @@ -939,7 +941,7 @@ func SendMessageWithTemplate(domain, apiKey string) error {
time.Sleep(time.Second * 1)

// Create a new message with template
m := mailgun.NewMessage("Excited User <[email protected]>", "Template example", "")
m := mailgun.NewMessage(domain, "Excited User <[email protected]>", "Template example", "")
m.SetTemplate("my-template")

// Add recipients
Expand Down
2 changes: 1 addition & 1 deletion examples_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ Testing some Mailgun MIME awesomeness!
defer cancel()

mg := mailgun.NewMailgun("example.com", "my_api_key")
m := mailgun.NewMIMEMessage(io.NopCloser(strings.NewReader(exampleMime)), "[email protected]")
m := mailgun.NewMIMEMessage("example.com", io.NopCloser(strings.NewReader(exampleMime)), "[email protected]")
_, id, err := mg.Send(ctx, m)
if err != nil {
log.Fatal(err)
Expand Down
5 changes: 2 additions & 3 deletions mailgun.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,8 @@ type Mailgun interface {
AddOverrideHeader(k string, v string)
GetCurlOutput() string

// Send attempts to queue a message (see Message, NewMessage, and its methods) for delivery.
// TODO(v5): switch m to SendableMessage interface
Send(ctx context.Context, m *Message) (mes string, id string, err error)
// Send attempts to queue a message (see CommonMessage, NewMessage, and its methods) for delivery.
Send(ctx context.Context, m SendableMessage) (mes string, id string, err error)
ReSend(ctx context.Context, id string, recipients ...string) (string, string, error)

ListBounces(opts *ListOptions) *BouncesIterator
Expand Down
Loading

0 comments on commit a2a4cfd

Please sign in to comment.