Skip to content

Commit

Permalink
Smtp support
Browse files Browse the repository at this point in the history
  • Loading branch information
mrz1836 committed Oct 12, 2019
1 parent 92d3e9b commit 534578c
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 5 deletions.
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/)
Expand Down Expand Up @@ -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).
Expand Down
76 changes: 76 additions & 0 deletions smtp.go
Original file line number Diff line number Diff line change
@@ -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()
}

0 comments on commit 534578c

Please sign in to comment.