forked from jhillyerd/enmime
-
Notifications
You must be signed in to change notification settings - Fork 1
/
sender.go
33 lines (27 loc) · 1.19 KB
/
sender.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
package enmime
import "net/smtp"
// Sender provides a method for enmime to send an email.
type Sender interface {
// Sends the provided msg to the specified recipients, providing the specified reverse-path to
// the mail server to use for delivery error reporting.
//
// The message headers should usually include fields such as "From", "To", "Subject", and "Cc".
// Sending "Bcc" messages is accomplished by including an email address in the recipients
// parameter but not including it in the message headers.
Send(reversePath string, recipients []string, msg []byte) error
}
// SMTPSender is a Sender backed by Go's built-in net/smtp.SendMail function.
type SMTPSender struct {
addr string
auth smtp.Auth
}
var _ Sender = &SMTPSender{}
// NewSMTP creates a new SMTPSender, which uses net/smtp.SendMail, and accepts the same
// authentication parameters. If no authentication is required, `auth` may be nil.
func NewSMTP(addr string, auth smtp.Auth) *SMTPSender {
return &SMTPSender{addr, auth}
}
// Send a message using net/smtp.SendMail.
func (s *SMTPSender) Send(reversePath string, recipients []string, msg []byte) error {
return smtp.SendMail(s.addr, s.auth, reversePath, recipients, msg)
}