mailx

package module
v0.5.20231221 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 21, 2023 License: MIT Imports: 16 Imported by: 2

README

Mailx

Go Report Card Go Reference GitHub License codecov

Mailx is a library that makes it easier to send email via SMTP. It is an enhancement of the golang standard library net/smtp.

Compatibility

  • Compatible with go 1.16+

Features

Gomail supports:

  • Attachments
  • Embedded files
  • HTML and text templates
  • TLS connection and STARTTLS extension
  • Sending multiple emails with the same SMTP connection

Installing

go mod:

go get github.com/valord577/mailx

Example

Changes

See the CHANGES for changes.

License

See the LICENSE for Rights and Limitations (MIT).

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CopyFunc

type CopyFunc func(io.Writer) (int, error)

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

func (d *Dialer) Dial() (*Sender, error)

Dial dials and authenticates to an SMTP server. The returned *Sender should be closed when done using it.

func (*Dialer) DialAndSend

func (d *Dialer) DialAndSend(m *Message) error

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 NewMessage

func NewMessage() *Message

NewMessage creates a new email message.

func (*Message) AddBcc added in v0.2.20211115

func (m *Message) AddBcc(address ...string)

AddBcc adds the header of email message: 'BCC'.

func (*Message) AddCc added in v0.2.20211115

func (m *Message) AddCc(address ...string)

AddCc adds the header of email message: 'CC'.

func (*Message) AddCopierBody added in v0.2.20211115

func (m *Message) AddCopierBody(contentType string, copier CopyFunc)

AddCopierBody adds a custom part of the body of email message.

func (*Message) AddHeader added in v0.2.20211115

func (m *Message) AddHeader(key string, value ...string)

AddHeader adds other headers of email message.

func (*Message) AddHtmlBody added in v0.2.20211115

func (m *Message) AddHtmlBody(html string)

AddHtmlBody adds a html part of the body of email message.

func (*Message) AddPlainBody added in v0.2.20211115

func (m *Message) AddPlainBody(text string)

AddPlainBody adds a text part of the body of email message.

func (*Message) AddRcptBcc added in v0.2.20211115

func (m *Message) AddRcptBcc(bcc ...*mail.Address)

AddRcptBcc adds the header of email message: 'BCC'.

func (*Message) AddRcptCc added in v0.2.20211115

func (m *Message) AddRcptCc(cc ...*mail.Address)

AddRcptCc adds the header of email message: 'CC'.

func (*Message) AddRcptTo added in v0.2.20211115

func (m *Message) AddRcptTo(to ...*mail.Address)

AddRcptTo adds the header of email message: 'TO'.

func (*Message) AddTo added in v0.2.20211115

func (m *Message) AddTo(address ...string)

AddTo adds the header of email message: 'TO'.

func (*Message) Attach added in v0.2.20211115

func (m *Message) Attach(filename string, copier CopyFunc)

Attach adds a attachment of email message.

func (*Message) Embed added in v0.2.20211115

func (m *Message) Embed(cid string, copier CopyFunc)

Embed adds a embedded file of email message.

func (*Message) SetBcc added in v0.2.20211115

func (m *Message) SetBcc(address ...string)

SetBcc sets the header of email message: 'BCC'.

func (*Message) SetCc added in v0.2.20211115

func (m *Message) SetCc(address ...string)

SetCc sets the header of email message: 'CC'.

func (*Message) SetCopierBody added in v0.2.20211115

func (m *Message) SetCopierBody(contentType string, copier CopyFunc)

SetCopierBody sets a custom part of the body of email message.

func (*Message) SetDate added in v0.2.20211115

func (m *Message) SetDate(datefmt string)

SetDate sets the header of email message: 'DATE'.

func (*Message) SetFrom added in v0.2.20211115

func (m *Message) SetFrom(sender *mail.Address)

SetFrom sets the header of email message: 'FROM'.

func (*Message) SetHtmlBody added in v0.2.20211115

func (m *Message) SetHtmlBody(html string)

SetHtmlBody sets a html part of the body of email message.

func (*Message) SetPlainBody added in v0.2.20211115

func (m *Message) SetPlainBody(text string)

SetPlainBody sets a text part of the body of email message.

func (*Message) SetRcptBcc added in v0.2.20211115

func (m *Message) SetRcptBcc(bcc ...*mail.Address)

SetRcptBcc sets the header of email message: 'BCC'.

func (*Message) SetRcptCc added in v0.2.20211115

func (m *Message) SetRcptCc(cc ...*mail.Address)

SetRcptCc sets the header of email message: 'CC'.

func (*Message) SetRcptTo added in v0.2.20211115

func (m *Message) SetRcptTo(to ...*mail.Address)

SetRcptTo sets the header of email message: 'TO'.

func (*Message) SetSender added in v0.2.20211115

func (m *Message) SetSender(address string)

SetSender sets the header of email message: 'FROM'.

func (*Message) SetSubject added in v0.2.20211115

func (m *Message) SetSubject(subject string)

SetSubject sets the header of email message: 'SUBJECT'.

func (*Message) SetTo added in v0.2.20211115

func (m *Message) SetTo(address ...string)

SetTo sets the header of email message: 'TO'.

func (*Message) SetUserAgent added in v0.2.20211115

func (m *Message) SetUserAgent(ua string)

SetUserAgent sets the header of email message: 'USER-AGENT'.

func (*Message) WriteTo added in v0.2.20211115

func (m *Message) WriteTo(w io.Writer) (int64, error)

WriteTo implements io.WriterTo. It dumps the whole message to SMTP server.

type Sender

type Sender struct {
	// contains filtered or unexported fields
}

Sender sends emails via *smtp.Client

func (*Sender) Close

func (s *Sender) Close() error

Close sends the QUIT command and closes the connection to the server.

func (*Sender) Send

func (s *Sender) Send(m *Message) error

Send sends the given emails.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL