Skip to content

Commit 534578c

Browse files
committed
Smtp support
1 parent 92d3e9b commit 534578c

2 files changed

Lines changed: 82 additions & 5 deletions

File tree

README.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,19 @@ $ dep ensure -update -v
3131

3232
### Package Dependencies
3333
- domodwyer's [mailyak](https://github.com/domodwyer/mailyak)
34-
- keighl's [postmark](https://github.com/keighl/postmark)
34+
- keighl's [postmark](https://github.com/mrz1836/postmark)
3535
- mattbaird's [gochimp](https://github.com/mattbaird/gochimp)
36-
- sourcegraph's [go-ses](https://github.com/sourcegraph/go-ses)
3736
- mrz1836's [go-logger](https://github.com/mrz1836/go-logger)
37+
- sourcegraph's [go-ses](https://github.com/sourcegraph/go-ses)
3838

3939
## Documentation
4040
You can view the generated [documentation here](https://godoc.org/github.com/mrz1836/go-mail).
4141

4242
### Supported Service Providers
43+
- [AWS SES](https://docs.aws.amazon.com/ses/)
4344
- [Mandrill](https://mandrillapp.com/api/docs/)
4445
- [Postmark](https://postmarkapp.com/developer)
45-
- [AWS SES](https://docs.aws.amazon.com/ses/)
46+
- [SMTP](https://en.wikipedia.org/wiki/Simple_Mail_Transfer_Protocol)
4647

4748
### Features
4849
- 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() {
103104
## Contributing
104105

105106
This project uses:
106-
- keighl's [postmark](https://github.com/keighl/postmark) package
107-
- mattbaird's [gochimp](https://github.com/mattbaird/gochimp) package
108107
- domodwyer's [mailyak](https://github.com/domodwyer/mailyak) package
108+
- keighl's [postmark](https://github.com/mrz1836/postmark) package
109+
- mattbaird's [gochimp](https://github.com/mattbaird/gochimp) package
109110
- sourcegraph's [go-ses](https://github.com/sourcegraph/go-ses) package
110111

111112
View the [contributing guidelines](CONTRIBUTING.md) and follow the [code of conduct](CODE_OF_CONDUCT.md).

smtp.go

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,77 @@
11
package gomail
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/domodwyer/mailyak"
7+
"github.com/mrz1836/go-logger"
8+
)
9+
10+
// sendWithSmtp sends an email using the smtp service
11+
func (m *MailService) sendWithSmtp(email *Email) (err error) {
12+
13+
// Create new mail message
14+
mail := mailyak.New(fmt.Sprintf("%s:%d", m.SmtpHost, m.SmtpPort), m.smtpAuth)
15+
16+
// Add the to recipients
17+
mail.To(email.Recipients...)
18+
19+
// Add the cc recipients
20+
if len(email.RecipientsCc) > 0 {
21+
mail.Cc(email.RecipientsCc...)
22+
}
23+
24+
// Add the bcc recipients
25+
if len(email.RecipientsBcc) > 0 {
26+
mail.WriteBccHeader(true)
27+
mail.Bcc(email.RecipientsBcc...)
28+
}
29+
30+
// Add the basics
31+
mail.From(email.FromAddress)
32+
mail.FromName(email.FromName)
33+
mail.Subject(email.Subject)
34+
35+
// Add a custom reply to address
36+
if len(email.ReplyToAddress) > 0 {
37+
mail.ReplyTo(email.ReplyToAddress)
38+
}
39+
40+
// Add plain text
41+
if len(email.PlainTextContent) > 0 {
42+
mail.Plain().Set(email.PlainTextContent)
43+
}
44+
45+
// Add html
46+
if len(email.HTMLContent) > 0 {
47+
mail.HTML().Set(email.HTMLContent)
48+
}
49+
50+
// Add any attachments
51+
if len(email.Attachments) > 0 {
52+
for _, att := range email.Attachments {
53+
mail.Attach(att.FileName, att.FileReader)
54+
}
55+
}
56+
57+
// Add importance?
58+
if email.Important {
59+
mail.AddHeader("X-Priority", "1 (Highest)")
60+
mail.AddHeader("X-MSMail-Priority", "High")
61+
mail.AddHeader("Importance", "High")
62+
}
63+
64+
// Warn about features that are set but not available
65+
if email.TrackClicks {
66+
logger.Data(2, logger.WARN, "track clicks is enabled, but aws ses does not offer this feature")
67+
}
68+
if email.TrackOpens {
69+
logger.Data(2, logger.WARN, "track opens is enabled, but aws ses does not offer this feature")
70+
}
71+
if email.AutoText {
72+
logger.Data(2, logger.WARN, "auto text is enabled, but aws ses does not offer this feature")
73+
}
74+
75+
// Send via smtp
76+
return mail.Send()
77+
}

0 commit comments

Comments
 (0)