README
¶
Mailx
Mailx is a library that makes it easier to send email via SMTP. It is an enhancement of the golang standard library net/smtp
.
Features
Gomail supports:
- Attachments and embedded files
- HTML and text templates
- TLS connection and STARTTLS extension
- Sending multiple emails with the same SMTP connection
- Single destination headers are used in compliance with RFC 5322 #7
Installing
go mod:
go get github.com/valord577/mailx
Example
- See example
Changes
See the CHANGES for changes.
License
See the LICENSE for Rights and Limitations (MIT).
Documentation
¶
Index ¶
- type CopyFunc
- type Dialer
- type Message
- func (m *Message) AddBcc(address ...string)
- func (m *Message) AddCc(address ...string)
- func (m *Message) AddCopierBody(contentType string, copier CopyFunc)
- func (m *Message) AddHeader(key string, value ...string)
- func (m *Message) AddHtmlBody(html string)
- func (m *Message) AddPlainBody(text string)
- func (m *Message) AddRcptBcc(bcc ...*mail.Address)
- func (m *Message) AddRcptCc(cc ...*mail.Address)
- func (m *Message) AddRcptTo(to ...*mail.Address)
- func (m *Message) AddTo(address ...string)
- func (m *Message) Attach(filename string, copier CopyFunc)
- func (m *Message) Embed(cid string, copier CopyFunc)
- func (m *Message) SetBcc(address ...string)
- func (m *Message) SetCc(address ...string)
- func (m *Message) SetCopierBody(contentType string, copier CopyFunc)
- func (m *Message) SetDate(datefmt string)
- func (m *Message) SetFrom(sender *mail.Address)
- func (m *Message) SetHtmlBody(html string)
- func (m *Message) SetPlainBody(text string)
- func (m *Message) SetRcptBcc(bcc ...*mail.Address)
- func (m *Message) SetRcptCc(cc ...*mail.Address)
- func (m *Message) SetRcptTo(to ...*mail.Address)
- func (m *Message) SetSender(address string)
- func (m *Message) SetSingleRecvAddr(single bool)
- func (m *Message) SetSubject(subject string)
- func (m *Message) SetTo(address ...string)
- func (m *Message) SetUserAgent(ua string)
- func (m *Message) WriteTo(w io.Writer) (int64, error)
- type Sender
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CopyFunc ¶
CopyFunc is the function that runs when the message is sent. It should copy the content of the emails to the io.Writer(SMTP).
type Dialer ¶
type Dialer struct { // Host represents the host of the SMTP server. Host string // Port represents the port of the SMTP server. Port int // Username is the username to use to authenticate to the SMTP server. Username string // Password is the password to use to authenticate to the SMTP server. Password string // SSLOnConnect defines whether an SSL connection is used. // It should be false while SMTP server use the STARTTLS extension. SSLOnConnect bool // TSLConfig represents the TLS configuration. // It is used for the TLS (when the // STARTTLS extension is used) or SSL connection. TLSConfig *tls.Config // Timeout is passed to net.Dialer's Timeout. Timeout time.Duration }
Dialer is a dialer to an SMTP server.
func (*Dialer) Dial ¶
Dial dials and authenticates to an SMTP server. The returned *Sender should be closed when done using it.
func (*Dialer) DialAndSend ¶
DialAndSend opens a connection to the SMTP server, sends the given emails and closes the connection.
type Message ¶ added in v0.2.20211115
type Message struct {
// contains filtered or unexported fields
}
Message represents an email message.
func (*Message) AddCopierBody ¶ added in v0.2.20211115
AddCopierBody adds a custom part of the body of email message.
func (*Message) AddHtmlBody ¶ added in v0.2.20211115
AddHtmlBody adds a html part of the body of email message.
func (*Message) AddPlainBody ¶ added in v0.2.20211115
AddPlainBody adds a text part of the body of email message.
func (*Message) AddRcptBcc ¶ added in v0.2.20211115
AddRcptBcc adds the header of email message: 'BCC'.
func (*Message) AddRcptCc ¶ added in v0.2.20211115
AddRcptCc adds the header of email message: 'CC'.
func (*Message) AddRcptTo ¶ added in v0.2.20211115
AddRcptTo adds the header of email message: 'TO'.
func (*Message) SetCopierBody ¶ added in v0.2.20211115
SetCopierBody sets a custom part of the body of email message.
func (*Message) SetHtmlBody ¶ added in v0.2.20211115
SetHtmlBody sets a html part of the body of email message.
func (*Message) SetPlainBody ¶ added in v0.2.20211115
SetPlainBody sets a text part of the body of email message.
func (*Message) SetRcptBcc ¶ added in v0.2.20211115
SetRcptBcc sets the header of email message: 'BCC'.
func (*Message) SetRcptCc ¶ added in v0.2.20211115
SetRcptCc sets the header of email message: 'CC'.
func (*Message) SetRcptTo ¶ added in v0.2.20211115
SetRcptTo sets the header of email message: 'TO'.
func (*Message) SetSender ¶ added in v0.2.20211115
SetSender sets the header of email message: 'FROM'.
func (*Message) SetSingleRecvAddr ¶ added in v0.6.20240511
SetSingleRecvAddr sets a flag which whether or not to let receiver's addresses in header combined into one line. see https://www.rfc-editor.org/rfc/rfc5322#section-3.6.3
func (*Message) SetSubject ¶ added in v0.2.20211115
SetSubject sets the header of email message: 'SUBJECT'.
func (*Message) SetUserAgent ¶ added in v0.2.20211115
SetUserAgent sets the header of email message: 'USER-AGENT'.