Skip to content

Commit

Permalink
feat(email_message): encapsulate EmailMessage and Attachment struct w…
Browse files Browse the repository at this point in the history
…ith private fields and add constructors

- Encapsulated the EmailMessage struct by making variables private
- Added getters and setters for EmailMessage variables
- Implemented custom MarshalJSON and UnmarshalJSON methods for EmailMessage
- Encapsulated the Attachment struct by making variables private
- Added getters and setters for variables
- Implemented custom MarshalJSON and UnmarshalJSON methods for Attachment
- Added a constructor for creating Attachment from filename and content
- Added a constructor for creating Attachment from a file path
- Create a testdata folder for adding test files
  • Loading branch information
JRocabruna committed Jun 6, 2024
1 parent 2f1f56b commit 2498c56
Show file tree
Hide file tree
Showing 29 changed files with 1,037 additions and 373 deletions.
4 changes: 1 addition & 3 deletions docs/AWS_SES_Credentials.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,7 @@ if err != nil {
// Define email message
message := gomail.NewEmailMessage(sender,[]string{"[email protected]"}, "Test Email with attachment", "This is the plain text part of the email.").
SetHTML("<p>This is the <b>HTML</b> part of the <i>email</i>.</p>").
AddAttachments(gomail.Attachment{
Filename: "attachment.jpg", Content: attachmentContent,
})
AddAttachments(*gomail.NewAttachment("attachment.jpg", attachmentContent))



Expand Down
4 changes: 1 addition & 3 deletions docs/Gmail_Credentials_API_Key.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@ if err != nil {

// Define email message using an alias email address
message := gomail.NewEmailMessage("[email protected]",[]string{"[email protected]"}, "Test Email with attachment", "This is the plain text part of the email.").
SetHTML("<p>This is the <b>HTML</b> part of the <i>email</i>.</p>").AddAttachments(gomail.Attachment{
Filename: "attachment.jpg", Content: attachmentContent,
})
SetHTML("<p>This is the <b>HTML</b> part of the <i>email</i>.</p>").AddAttachments(*gomail.NewAttachment("attachment.jpg", attachmentContent))



Expand Down
4 changes: 1 addition & 3 deletions docs/Gmail_Credentials_JWT.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,7 @@ if err != nil {

// Define email message using an alias email address
message := gomail.NewEmailMessage("[email protected]",[]string{"[email protected]"}, "Test Email with attachment", "This is the plain text part of the email.").
SetHTML("<p>This is the <b>HTML</b> part of the <i>email</i>.</p>").AddAttachments(gomail.Attachment{
Filename: "attachment.jpg", Content: attachmentContent,
})
SetHTML("<p>This is the <b>HTML</b> part of the <i>email</i>.</p>").AddAttachments(*gomail.NewAttachment("attachment.jpg", attachmentContent))

// Send email
if err := emailSender.SendEmail(message); err != nil {
Expand Down
4 changes: 1 addition & 3 deletions docs/Gmail_Credentials_OAuth2.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,7 @@ if err != nil {

// Define email message using an alias email address
message := gomail.NewEmailMessage("[email protected]",[]string{"[email protected]"}, "Test Email with attachment", "This is the plain text part of the email.").
SetHTML("<p>This is the <b>HTML</b> part of the <i>email</i>.</p>").AddAttachments(gomail.Attachment{
Filename: "attachment.jpg", Content: attachmentContent,
})
SetHTML("<p>This is the <b>HTML</b> part of the <i>email</i>.</p>").AddAttachments(*gomail.NewAttachment("attachment.jpg", attachmentContent))

// Send email
if err := emailSender.SendEmail(message); err != nil {
Expand Down
4 changes: 1 addition & 3 deletions docs/Gmail_Credentials_ServiceAccount copy.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,7 @@ if err != nil {

// Define email message using an alias email address
message := gomail.NewEmailMessage("[email protected]",[]string{"[email protected]"}, "Test Email with attachment", "This is the plain text part of the email.").
SetHTML("<p>This is the <b>HTML</b> part of the <i>email</i>.</p>").AddAttachments(gomail.Attachment{
Filename: "attachment.jpg", Content: attachmentContent,
})
SetHTML("<p>This is the <b>HTML</b> part of the <i>email</i>.</p>").AddAttachments(*gomail.NewAttachment("attachment.jpg", attachmentContent))

// Send email
if err := emailSender.SendEmail(message); err != nil {
Expand Down
4 changes: 1 addition & 3 deletions docs/Gmail_Credentials_ServiceAccount.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,7 @@ if err != nil {

// Define email message using an alias email address
message := gomail.NewEmailMessage("[email protected]",[]string{"[email protected]"}, "Test Email with attachment", "This is the plain text part of the email.").
SetHTML("<p>This is the <b>HTML</b> part of the <i>email</i>.</p>").AddAttachments(gomail.Attachment{
Filename: "attachment.jpg", Content: attachmentContent,
})
SetHTML("<p>This is the <b>HTML</b> part of the <i>email</i>.</p>").AddAttachments(*gomail.NewAttachment("attachment.jpg", attachmentContent))

// Send email
if err := emailSender.SendEmail(message); err != nil {
Expand Down
4 changes: 1 addition & 3 deletions docs/Mailgun_Credentials.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@ if err != nil {

// Define email message
message := gomail.NewEmailMessage("[email protected]",[]string{"[email protected]"}, "Test Email with attachment", "This is the plain text part of the email.").
SetHTML("<p>This is the <b>HTML</b> part of the <i>email</i>.</p>").AddAttachments(gomail.Attachment{
Filename: "attachment.jpg", Content: attachmentContent,
})
SetHTML("<p>This is the <b>HTML</b> part of the <i>email</i>.</p>").AddAttachments(*gomail.NewAttachment("attachment.jpg", attachmentContent))

// Send email
if err := emailSender.SendEmail(message); err != nil {
Expand Down
4 changes: 1 addition & 3 deletions docs/Mandrill_Credentials.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@ if err != nil {

// Define email message
message := gomail.NewEmailMessage("[email protected]",[]string{"[email protected]"}, "Test Email with attachment", "This is the plain text part of the email.").
SetHTML("<p>This is the <b>HTML</b> part of the <i>email</i>.</p>").AddAttachments(gomail.Attachment{
Filename: "attachment.jpg", Content: attachmentContent,
})
SetHTML("<p>This is the <b>HTML</b> part of the <i>email</i>.</p>").AddAttachments(*gomail.NewAttachment("attachment.jpg", attachmentContent))

// Send email
if err := emailSender.SendEmail(message); err != nil {
Expand Down
4 changes: 1 addition & 3 deletions docs/Microsoft365_Credentials_ROPC.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,7 @@ if err != nil {

// Define email message
message := gomail.NewEmailMessage("[email protected]",[]string{"[email protected]"}, "Test Email with attachment", "This is the plain text part of the email.").
SetHTML("<p>This is the <b>HTML</b> part of the <i>email</i>.</p>").AddAttachments(gomail.Attachment{
Filename: "attachment.jpg", Content: attachmentContent,
})
SetHTML("<p>This is the <b>HTML</b> part of the <i>email</i>.</p>").AddAttachments(*gomail.NewAttachment("attachment.jpg", attachmentContent))

// Send email
if err := emailSender.SendEmail(message); err != nil {
Expand Down
4 changes: 1 addition & 3 deletions docs/Microsoft365_Credentials_app.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,7 @@ if err != nil {

// Define email message
message := gomail.NewEmailMessage("[email protected]",[]string{"[email protected]"}, "Test Email with attachment", "This is the plain text part of the email.").
SetHTML("<p>This is the <b>HTML</b> part of the <i>email</i>.</p>").AddAttachments(gomail.Attachment{
Filename: "attachment.jpg", Content: attachmentContent,
})
SetHTML("<p>This is the <b>HTML</b> part of the <i>email</i>.</p>").AddAttachments(*gomail.NewAttachment("attachment.jpg", attachmentContent))

// Send email
if err := emailSender.SendEmail(message); err != nil {
Expand Down
4 changes: 1 addition & 3 deletions docs/Microsoft365_Credentials_credentials.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,7 @@ if err != nil {

// Define email message
message := gomail.NewEmailMessage("[email protected]",[]string{"[email protected]"}, "Test Email with attachment", "This is the plain text part of the email.").
SetHTML("<p>This is the <b>HTML</b> part of the <i>email</i>.</p>").AddAttachments(gomail.Attachment{
Filename: "attachment.jpg", Content: attachmentContent,
})
SetHTML("<p>This is the <b>HTML</b> part of the <i>email</i>.</p>").AddAttachments(*gomail.NewAttachment("attachment.jpg", attachmentContent))

// Send email
if err := emailSender.SendEmail(message); err != nil {
Expand Down
4 changes: 1 addition & 3 deletions docs/Microsoft365_Credentials_managed_id.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@ if err != nil {

// Define email message
message := gomail.NewEmailMessage("[email protected]",[]string{"[email protected]"}, "Test Email with attachment", "This is the plain text part of the email.").
SetHTML("<p>This is the <b>HTML</b> part of the <i>email</i>.</p>").AddAttachments(gomail.Attachment{
Filename: "attachment.jpg", Content: attachmentContent,
})
SetHTML("<p>This is the <b>HTML</b> part of the <i>email</i>.</p>").AddAttachments(*gomail.NewAttachment("attachment.jpg", attachmentContent))

// Send email
if err := emailSender.SendEmail(message); err != nil {
Expand Down
4 changes: 1 addition & 3 deletions docs/Microsoft365_Credentials_user.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,7 @@ if err != nil {

// Define email message
message := gomail.NewEmailMessage("[email protected]",[]string{"[email protected]"}, "Test Email with attachment", "This is the plain text part of the email.").
SetHTML("<p>This is the <b>HTML</b> part of the <i>email</i>.</p>").AddAttachments(gomail.Attachment{
Filename: "attachment.jpg", Content: attachmentContent,
})
SetHTML("<p>This is the <b>HTML</b> part of the <i>email</i>.</p>").AddAttachments(*gomail.NewAttachment("attachment.jpg", attachmentContent))

// Send email
if err := emailSender.SendEmail(message); err != nil {
Expand Down
4 changes: 1 addition & 3 deletions docs/Postmark_Credentials.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ if err != nil {

// Define email message
message := gomail.NewEmailMessage("[email protected]",[]string{"[email protected]"}, "Test Email with attachment", "This is the plain text part of the email.").
SetHTML("<p>This is the <b>HTML</b> part of the <i>email</i>.</p>").AddAttachments(gomail.Attachment{
Filename: "attachment.jpg", Content: attachmentContent,
})
SetHTML("<p>This is the <b>HTML</b> part of the <i>email</i>.</p>").AddAttachments(*gomail.NewAttachment("attachment.jpg", attachmentContent))

// Send email
if err := emailSender.SendEmail(message); err != nil {
Expand Down
4 changes: 1 addition & 3 deletions docs/SMTP_Credentials.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@ if err != nil {

// Define email message
message := gomail.NewEmailMessage("[email protected]",[]string{"[email protected]"}, "Test Email with attachment", "This is the plain text part of the email.").
SetHTML("<p>This is the <b>HTML</b> part of the <i>email</i>.</p>").AddAttachments(gomail.Attachment{
Filename: "attachment.jpg", Content: attachmentContent,
})
SetHTML("<p>This is the <b>HTML</b> part of the <i>email</i>.</p>").AddAttachments(*gomail.NewAttachment("attachment.jpg", attachmentContent))

// Send email
if err := emailSender.SendEmail(message); err != nil {
Expand Down
4 changes: 1 addition & 3 deletions docs/SendGrid_Credentials.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@ if err != nil {

// Define email message
message := gomail.NewEmailMessage("[email protected]",[]string{"[email protected]"}, "Test Email with attachment", "This is the plain text part of the email.").
SetHTML("<p>This is the <b>HTML</b> part of the <i>email</i>.</p>").AddAttachments(gomail.Attachment{
Filename: "attachment.jpg", Content: attachmentContent,
})
SetHTML("<p>This is the <b>HTML</b> part of the <i>email</i>.</p>").AddAttachments(*gomail.NewAttachment("attachment.jpg", attachmentContent))

// Send email
if err := emailSender.SendEmail(message); err != nil {
Expand Down
Loading

0 comments on commit 2498c56

Please sign in to comment.