File: sender.go

package info (click to toggle)
golang-github-jhillyerd-enmime 0.9.3-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,156 kB
  • sloc: makefile: 25; sh: 16
file content (33 lines) | stat: -rw-r--r-- 1,216 bytes parent folder | download | duplicates (2)
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)
}