-
Notifications
You must be signed in to change notification settings - Fork 52
/
mail.go
51 lines (43 loc) · 1.02 KB
/
mail.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package main
import (
stdMail "net/mail"
"github.com/zachlatta/postman/mail"
"gopkg.in/jordan-wright/email.v2"
)
func sendMail(recipient Recipient, emailField string, mailer *mail.Mailer,
debug bool, success chan *email.Email, fail chan error) {
parsedSender, err := stdMail.ParseAddress(sender)
if err != nil {
fail <- err
return
}
parsedTo, err := stdMail.ParseAddress(recipient[emailField])
if err != nil {
fail <- err
return
}
// Should probably add a clearer distinction somewhere, but in the case that
// the user doesn't provide the -html flag, htmlTemplatePath will be an empty
// string. If it's an empty string, then it'll be ignored and not parsed and
// added to the message within the mail.NewMessage method.
message, err := mail.NewMessage(
parsedSender,
parsedTo,
subject,
files,
textTemplatePath,
htmlTemplatePath,
recipient,
)
if err != nil {
fail <- err
return
}
if !debug {
if err := mailer.Send(message); err != nil {
fail <- err
return
}
}
success <- message
}