Debian Codegraph @

sender.go

raw
1 package enmime
2
3 import "net/smtp"
4
5 // Sender provides a method for enmime to send an email.
6 type Sender interface {
7 // Sends the provided msg to the specified recipients, providing the specified reverse-path to
8 // the mail server to use for delivery error reporting.
9 //
10 // The message headers should usually include fields such as "From", "To", "Subject", and "Cc".
11 // Sending "Bcc" messages is accomplished by including an email address in the recipients
12 // parameter but not including it in the message headers.
13 Send(reversePath string, recipients []string, msg []byte) error
14 }
15
16 // SMTPSender is a Sender backed by Go's built-in net/smtp.SendMail function.
17 type SMTPSender struct {
18 addr string
19 auth smtp.Auth
20 }
21
22 var _ Sender = &SMTPSender{}
23
24 // NewSMTP creates a new SMTPSender, which uses net/smtp.SendMail, and accepts the same
25 // authentication parameters. If no authentication is required, `auth` may be nil.
26 func NewSMTP(addr string, auth smtp.Auth) *SMTPSender {
27 return &SMTPSender{addr, auth}
28 }
29
30 // Send a message using net/smtp.SendMail.
31 func (s *SMTPSender) Send(reversePath string, recipients []string, msg []byte) error {
32 return smtp.SendMail(s.addr, s.auth, reversePath, recipients, msg)
33 }