diff --git a/README.md b/README.md index f9f0aa4..b91216c 100644 --- a/README.md +++ b/README.md @@ -31,18 +31,19 @@ $ dep ensure -update -v ### Package Dependencies - domodwyer's [mailyak](https://github.com/domodwyer/mailyak) -- keighl's [postmark](https://github.com/keighl/postmark) +- keighl's [postmark](https://github.com/mrz1836/postmark) - mattbaird's [gochimp](https://github.com/mattbaird/gochimp) -- sourcegraph's [go-ses](https://github.com/sourcegraph/go-ses) - mrz1836's [go-logger](https://github.com/mrz1836/go-logger) +- sourcegraph's [go-ses](https://github.com/sourcegraph/go-ses) ## Documentation You can view the generated [documentation here](https://godoc.org/github.com/mrz1836/go-mail). ### Supported Service Providers +- [AWS SES](https://docs.aws.amazon.com/ses/) - [Mandrill](https://mandrillapp.com/api/docs/) - [Postmark](https://postmarkapp.com/developer) -- [AWS SES](https://docs.aws.amazon.com/ses/) +- [SMTP](https://en.wikipedia.org/wiki/Simple_Mail_Transfer_Protocol) ### Features - Uses MrZ's [go-logger](https://github.com/mrz1836/go-logger) for either local or remote logging via [LogEntries](https://logentries.com/) @@ -103,9 +104,9 @@ func main() { ## Contributing This project uses: -- keighl's [postmark](https://github.com/keighl/postmark) package -- mattbaird's [gochimp](https://github.com/mattbaird/gochimp) package - domodwyer's [mailyak](https://github.com/domodwyer/mailyak) package +- keighl's [postmark](https://github.com/mrz1836/postmark) package +- mattbaird's [gochimp](https://github.com/mattbaird/gochimp) package - sourcegraph's [go-ses](https://github.com/sourcegraph/go-ses) package View the [contributing guidelines](CONTRIBUTING.md) and follow the [code of conduct](CODE_OF_CONDUCT.md). diff --git a/smtp.go b/smtp.go index 4543bef..ab2cdce 100644 --- a/smtp.go +++ b/smtp.go @@ -1 +1,77 @@ package gomail + +import ( + "fmt" + + "github.com/domodwyer/mailyak" + "github.com/mrz1836/go-logger" +) + +// sendWithSmtp sends an email using the smtp service +func (m *MailService) sendWithSmtp(email *Email) (err error) { + + // Create new mail message + mail := mailyak.New(fmt.Sprintf("%s:%d", m.SmtpHost, m.SmtpPort), m.smtpAuth) + + // Add the to recipients + mail.To(email.Recipients...) + + // Add the cc recipients + if len(email.RecipientsCc) > 0 { + mail.Cc(email.RecipientsCc...) + } + + // Add the bcc recipients + if len(email.RecipientsBcc) > 0 { + mail.WriteBccHeader(true) + mail.Bcc(email.RecipientsBcc...) + } + + // Add the basics + mail.From(email.FromAddress) + mail.FromName(email.FromName) + mail.Subject(email.Subject) + + // Add a custom reply to address + if len(email.ReplyToAddress) > 0 { + mail.ReplyTo(email.ReplyToAddress) + } + + // Add plain text + if len(email.PlainTextContent) > 0 { + mail.Plain().Set(email.PlainTextContent) + } + + // Add html + if len(email.HTMLContent) > 0 { + mail.HTML().Set(email.HTMLContent) + } + + // Add any attachments + if len(email.Attachments) > 0 { + for _, att := range email.Attachments { + mail.Attach(att.FileName, att.FileReader) + } + } + + // Add importance? + if email.Important { + mail.AddHeader("X-Priority", "1 (Highest)") + mail.AddHeader("X-MSMail-Priority", "High") + mail.AddHeader("Importance", "High") + } + + // Warn about features that are set but not available + if email.TrackClicks { + logger.Data(2, logger.WARN, "track clicks is enabled, but aws ses does not offer this feature") + } + if email.TrackOpens { + logger.Data(2, logger.WARN, "track opens is enabled, but aws ses does not offer this feature") + } + if email.AutoText { + logger.Data(2, logger.WARN, "auto text is enabled, but aws ses does not offer this feature") + } + + // Send via smtp + return mail.Send() +}