-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from mapreal19/juanito/feat/mailgun
Mailgun added
- Loading branch information
Showing
6 changed files
with
83 additions
and
8 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
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 |
---|---|---|
|
@@ -17,7 +17,7 @@ var _ = Describe("mailer", func() { | |
envs.Init("") | ||
_ = os.Setenv("BEEGO_ENV", "test") | ||
|
||
mailer.Init("dontNeeded") | ||
mailer.Init("dontNeeded", mailer.Provider.SendGrid) | ||
var email mailer.Email | ||
email.From = "[email protected]" | ||
email.FromName = "M. Bison" | ||
|
@@ -47,7 +47,7 @@ var _ = Describe("mailer", func() { | |
It("get attachment", func() { | ||
envs.Init("") | ||
_ = os.Setenv("BEEGO_ENV", "test") | ||
mailer.Init("dontNeeded") | ||
mailer.Init("dontNeeded", mailer.Provider.SendGrid) | ||
|
||
var attachement mailer.Attachment | ||
attachement.Name = "hello.txt" | ||
|
@@ -73,7 +73,7 @@ var _ = Describe("mailer", func() { | |
It("get same file parameters", func() { | ||
envs.Init("") | ||
_ = os.Setenv("BEEGO_ENV", "test") | ||
mailer.Init("dontNeeded") | ||
mailer.Init("dontNeeded", mailer.Provider.SendGrid) | ||
|
||
var email mailer.Email | ||
email.From = "[email protected]" | ||
|
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 |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package mailer | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/astaxie/beego" | ||
"github.com/mailgun/mailgun-go" | ||
) | ||
|
||
func newMailgunSender() *emailSender { | ||
return &emailSender{mailgunSender} | ||
} | ||
|
||
func mailgunSender(email Email) { | ||
beego.Info("Sending email through MailGun... Recipient: ", email.Tos[0]) | ||
mg := mailgun.NewMailgun(os.Getenv("MAILGUN_DOMAIN"), apiKey) | ||
|
||
message := mg.NewMessage( | ||
fmt.Sprint("%s<%s>", email.FromName, email.From), | ||
email.Subject, | ||
email.PlainBody, | ||
email.Tos...) | ||
|
||
mailGunAddCCs(message, email.Ccs) | ||
mailGunAddBCCs(message, email.Bccs) | ||
mailGunAddAttachments(message, email.Attachments) | ||
message.SetHtml(email.Body) | ||
|
||
mg.Send(message) | ||
|
||
} | ||
func mailGunAddAttachments(message *mailgun.Message, attachment []Attachment) { | ||
for _, att := range attachment { | ||
message.AddBufferAttachment(att.Name, att.Data) | ||
} | ||
} | ||
|
||
func mailGunAddCCs(message *mailgun.Message, addresses []string) { | ||
for _, addr := range addresses { | ||
message.AddCC(addr) | ||
} | ||
} | ||
|
||
func mailGunAddBCCs(message *mailgun.Message, addresses []string) { | ||
for _, addr := range addresses { | ||
message.AddBCC(addr) | ||
} | ||
} |
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