Skip to content

Commit

Permalink
switched to mailgun.NewMessage()
Browse files Browse the repository at this point in the history
  • Loading branch information
vtopc committed Oct 31, 2024
1 parent bc931b0 commit eaf99e7
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 55 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,6 @@ func main() {

// Send the message with a 10-second timeout
resp, id, err := mg.Send(ctx, message)

if err != nil {
log.Fatal(err)
}
Expand Down
2 changes: 1 addition & 1 deletion attachments_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func TestMultipleAttachments(t *testing.T) {

var ctx = context.Background()

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

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

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

Expand Down Expand Up @@ -126,7 +126,7 @@ func ExampleMailgunImpl_ListEvents() {
for it.Next(ctx, &page) {
for _, e := range page {
// You can access some fields via the interface
//fmt.Printf("Event: '%s' TimeStamp: '%s'\n", e.GetName(), e.GetTimestamp())
// fmt.Printf("Event: '%s' TimeStamp: '%s'\n", e.GetName(), e.GetTimestamp())

// and you can act upon each event by type
switch event := e.(type) {
Expand Down
18 changes: 9 additions & 9 deletions examples/examples.go
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,7 @@ 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!",
Expand All @@ -718,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!",
Expand All @@ -737,7 +737,7 @@ 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!",
Expand All @@ -757,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!",
Expand Down Expand Up @@ -790,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!",
Expand All @@ -807,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!",
Expand All @@ -823,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!",
Expand All @@ -844,7 +844,7 @@ 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%",
Expand Down Expand Up @@ -938,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
Expand Down
2 changes: 1 addition & 1 deletion examples_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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!",
Expand Down
12 changes: 8 additions & 4 deletions messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,13 @@ type TrackingOptions struct {
}

// features abstracts the common characteristics between regular and MIME messages.
// addCC, addBCC, recipientCount, setHtml and setAMPHtml are invoked via the package-global AddCC, AddBCC,
// RecipientCount, SetHtml and SetAMPHtml calls, as these functions are ignored for MIME messages.
// addCC, addBCC, recipientCount, setHtml and setAMPHtml are invoked via the AddCC, AddBCC,
// RecipientCount, SetHTML and SetAMPHtml calls, as these functions are ignored for MIME messages.
// Send() invokes addValues to add message-type-specific MIME headers for the API call
// to Mailgun. isValid yeilds true if and only if the message is valid enough for sending
// through the API. Finally, endpoint() tells Send() which endpoint to use to submit the API call.
// to Mailgun.
// isValid yields true if and only if the message is valid enough for sending
// through the API.
// Finally, endpoint() tells Send() which endpoint to use to submit the API call.
type features interface {
addCC(string)
addBCC(string)
Expand Down Expand Up @@ -433,6 +435,8 @@ func (m *Message) SetDeliveryTime(dt time.Time) {
// Refer to the Mailgun documentation for more information.
func (m *Message) SetSTOPeriod(stoPeriod string) error {
validPattern := `^([2-6][4-9]|[3-6][0-9]|7[0-2])h$`
// TODO(vtopc): regexp.Compile, which is called by regexp.MatchString, is a heave operation, move into global variable
// or just parse using time.ParseDuration().
match, err := regexp.MatchString(validPattern, stoPeriod)
if err != nil {
return err
Expand Down
Loading

0 comments on commit eaf99e7

Please sign in to comment.