-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Sarah Funkhouser <[email protected]>
- Loading branch information
1 parent
0877c7c
commit bc8679a
Showing
14 changed files
with
259 additions
and
95 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
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,16 +39,21 @@ import ( | |
) | ||
|
||
func main() { | ||
sender, err := resend.New("your_resend_api_token") | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
msg := newman.NewEmailMessage("[email protected]", []string{"[email protected]"}, "Isnt sending emails with golang fun?", "Oh Yes! Mark my words, Seinfeld! Your day of reckoning is coming") | ||
|
||
if err := sender.SendEmail(msg); err != nil { | ||
log.Fatal(err) | ||
} | ||
sender, err := resend.New("your_resend_api_token") | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
msg := newman.NewEmailMessageWithOptions( | ||
newman.WithFrom("[email protected]"), | ||
newman.WithTo([]string{"[email protected]"}), | ||
newman.WithSubject("Isn't sending emails with golang fun?"), | ||
newman.WithHTML("<p>Oh Yes! Mark my words, Seinfeld! Your day of reckoning is coming</p>"), | ||
) | ||
|
||
if err := sender.SendEmail(msg); 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,30 +28,28 @@ func TestNewEmailMessage(t *testing.T) { | |
assert.Empty(t, emailMessage.GetHTML()) | ||
} | ||
|
||
func TestNewFullEmailMessage(t *testing.T) { | ||
func TestNewEmailMessageWithOptions(t *testing.T) { | ||
from := "[email protected]" | ||
to := []string{"[email protected]"} | ||
cc := []string{"[email protected]"} | ||
bcc := []string{"[email protected]"} | ||
replyTo := "[email protected]" | ||
subject := "Look sister, go get yourself a cup of coffee or something" | ||
textBody := "Ill tell you a little secret about ZIP codes - they are meaningless" | ||
htmlBody := "<p>This is a test HTML body.</p>" | ||
attachments := []*Attachment{ | ||
NewAttachment("test.txt", []byte("test content")), | ||
} | ||
body := "And three times a week I shall require a cannoli" | ||
html := "<p>And three times a week I shall require a cannoli</p>" | ||
|
||
emailMessage := NewFullEmailMessage(from, to, subject, cc, bcc, replyTo, textBody, htmlBody, attachments) | ||
emailMessage := NewEmailMessageWithOptions( | ||
WithFrom(from), | ||
WithTo(to), | ||
WithSubject(subject), | ||
WithText(body), | ||
WithHTML(html), | ||
) | ||
|
||
assert.Equal(t, from, emailMessage.GetFrom()) | ||
assert.Equal(t, to, emailMessage.GetTo()) | ||
assert.Equal(t, cc, emailMessage.GetCC()) | ||
assert.Equal(t, bcc, emailMessage.GetBCC()) | ||
assert.Equal(t, replyTo, emailMessage.GetReplyTo()) | ||
assert.Equal(t, subject, emailMessage.GetSubject()) | ||
assert.Equal(t, textBody, emailMessage.GetText()) | ||
assert.Equal(t, htmlBody, emailMessage.GetHTML()) | ||
assert.Equal(t, attachments, emailMessage.GetAttachments()) | ||
assert.Equal(t, body, emailMessage.GetText()) | ||
assert.Equal(t, html, emailMessage.GetHTML()) | ||
assert.Empty(t, emailMessage.GetBCC()) | ||
assert.Empty(t, emailMessage.GetCC()) | ||
} | ||
|
||
func TestNewAttachment(t *testing.T) { | ||
|
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
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 |
---|---|---|
|
@@ -123,13 +123,17 @@ func TestSendEmail(t *testing.T) { | |
emailSender, err := New(apiKey, WithClient(mc)) | ||
assert.NoError(t, err) | ||
|
||
message := newman.NewEmailMessage("[email protected]", []string{"[email protected]"}, "Test Email", "The air is so dewy sweet you dont even have to lick the stamps"). | ||
SetCC([]string{"[email protected]"}). | ||
SetBCC([]string{"[email protected]"}). | ||
SetReplyTo("[email protected]"). | ||
SetHTML("<p>The air is so dewy sweet you dont even have to lick the stamps</p>"). | ||
SetBCC([]string{"[email protected]"}). | ||
AddAttachment(newman.NewAttachment("test.txt", []byte("When you control the mail, you control… INFORMATION!"))) | ||
message := newman.NewEmailMessageWithOptions( | ||
newman.WithFrom("[email protected]"), | ||
newman.WithTo([]string{"[email protected]"}), | ||
newman.WithSubject("Test Email"), | ||
newman.WithText("The air is so dewy sweet you dont even have to lick the stamps"), | ||
newman.WithCc([]string{"[email protected]"}), | ||
newman.WithBcc([]string{"[email protected]"}), | ||
newman.WithReplyTo("[email protected]"), | ||
newman.WithHTML("<p>The air is so dewy sweet you dont even have to lick the stamps</p>"), | ||
newman.WithAttachment(newman.NewAttachment("test.txt", []byte("When you control the mail, you control… INFORMATION!"))), | ||
) | ||
|
||
err = emailSender.SendEmailWithContext(context.Background(), message) | ||
assert.NoError(t, err) | ||
|
@@ -147,15 +151,45 @@ func TestSendEmailError(t *testing.T) { | |
emailSender, err := New(apiKey, WithClient(mc)) | ||
assert.NoError(t, err) | ||
|
||
message := newman.NewEmailMessage("[email protected]", []string{"[email protected]"}, "Test Email", "The air is so dewy sweet you dont even have to lick the stamps"). | ||
SetCC([]string{"[email protected]"}). | ||
SetBCC([]string{"[email protected]"}). | ||
SetReplyTo("[email protected]"). | ||
SetHTML("<p>The air is so dewy sweet you dont even have to lick the stamps</p>"). | ||
SetBCC([]string{"[email protected]"}). | ||
AddAttachment(newman.NewAttachment("test.txt", []byte("When you control the mail, you control… INFORMATION!"))) | ||
message := newman.NewEmailMessageWithOptions( | ||
newman.WithFrom("[email protected]"), | ||
newman.WithTo([]string{"[email protected]"}), | ||
newman.WithSubject("Test Email"), | ||
newman.WithText("The air is so dewy sweet you dont even have to lick the stamps"), | ||
newman.WithCc([]string{"[email protected]"}), | ||
newman.WithBcc([]string{"[email protected]"}), | ||
newman.WithReplyTo("[email protected]"), | ||
newman.WithHTML("<p>The air is so dewy sweet you dont even have to lick the stamps</p>"), | ||
newman.WithAttachment(newman.NewAttachment("test.txt", []byte("When you control the mail, you control… INFORMATION!"))), | ||
) | ||
|
||
err = emailSender.SendEmailWithContext(context.Background(), message) | ||
assert.Error(t, err) | ||
assert.ErrorIs(t, err, ErrFailedToSendEmail) | ||
} | ||
|
||
func TestSendEmailValidatFail(t *testing.T) { | ||
apiKey := "re_send_api_key" // #nosec G101 | ||
|
||
mc, ts := mockClient(t, apiKey, false) | ||
defer ts.Close() | ||
|
||
emailSender, err := New(apiKey, WithClient(mc)) | ||
assert.NoError(t, err) | ||
|
||
message := newman.NewEmailMessageWithOptions( | ||
newman.WithFrom("[email protected]"), | ||
newman.WithTo([]string{"jerry"}), // invalid email | ||
newman.WithSubject("Test Email"), | ||
newman.WithText("The air is so dewy sweet you dont even have to lick the stamps"), | ||
newman.WithCc([]string{"[email protected]"}), | ||
newman.WithBcc([]string{"[email protected]"}), | ||
newman.WithReplyTo("[email protected]"), | ||
newman.WithHTML("<p>The air is so dewy sweet you dont even have to lick the stamps</p>"), | ||
newman.WithAttachment(newman.NewAttachment("test.txt", []byte("When you control the mail, you control… INFORMATION!"))), | ||
) | ||
|
||
err = emailSender.SendEmailWithContext(context.Background(), message) | ||
assert.Error(t, err) | ||
assert.ErrorContains(t, err, "to is required") | ||
} |
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 |
---|---|---|
|
@@ -11,25 +11,25 @@ Example: | |
```go | ||
import ( | ||
"github.com/theopenlane/newman/scrubber" | ||
"github.com/theopenlane/newman/shared" | ||
"github.com/theopenlane/newman" | ||
"html" | ||
"strings" | ||
) | ||
|
||
func main() { | ||
email := shared.NewEmailMessage("[email protected]", []string{"[email protected]"}, "Subject", "<p>HTML content</p>") | ||
email := newman.NewEmailMessage("[email protected]", []string{"[email protected]"}, "Subject", "<p>HTML content</p>") | ||
|
||
customTextScrubber := scrubber.ScrubberFunc(func(content string) string { | ||
Implement your custom scrubber logic | ||
return strings.ToLower(strings.TrimSpace(content)) | ||
}) | ||
customTextScrubber := scrubber.ScrubberFunc(func(content string) string { | ||
//Implement your custom scrubber logic | ||
return strings.ToLower(strings.TrimSpace(content)) | ||
}) | ||
|
||
customHtmlScrubber := scrubber.ScrubberFunc(func(content string) string { | ||
Implement your custom scrubber logic | ||
return html.EscapeString(content) | ||
}) | ||
customHtmlScrubber := scrubber.ScrubberFunc(func(content string) string { | ||
//Implement your custom scrubber logic | ||
return html.EscapeString(content) | ||
}) | ||
|
||
email.SetCustomTextScrubber(customTextScrubber) | ||
email.SetCustomHtmlScrubber(customHtmlScrubber) | ||
email.SetCustomTextScrubber(customTextScrubber) | ||
email.SetCustomHTMLScrubber(customHtmlScrubber) | ||
} | ||
``` |
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.