mailx

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2023 License: MIT Imports: 16 Imported by: 0

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

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

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

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

func (*Message) AddCc

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

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

func (*Message) AddCopierBody

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

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

func (*Message) AddHeader

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

AddHeader adds other headers of email message.

func (*Message) AddHtmlBody

func (m *Message) AddHtmlBody(html string)

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

func (*Message) AddPlainBody

func (m *Message) AddPlainBody(text string)

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

func (*Message) AddRcptBcc

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

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

func (*Message) AddRcptCc

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

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

func (*Message) AddRcptTo

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

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

func (*Message) AddTo

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

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

func (*Message) Attach

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

Attach adds a attachment of email message.

func (*Message) Embed

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

Embed adds a embedded file of email message.

func (*Message) SetBcc

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

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

func (*Message) SetCc

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

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

func (*Message) SetCopierBody

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

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

func (*Message) SetDate

func (m *Message) SetDate(datefmt string)

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

func (*Message) SetHtmlBody

func (m *Message) SetHtmlBody(html string)

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

func (*Message) SetPlainBody

func (m *Message) SetPlainBody(text string)

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

func (*Message) SetRcptBcc

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

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

func (*Message) SetRcptCc

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

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

func (*Message) SetRcptTo

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

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

func (*Message) SetSubject

func (m *Message) SetSubject(subject string)

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

func (*Message) SetTo

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

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

func (*Message) SetUserAgent

func (m *Message) SetUserAgent(ua string)

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

func (*Message) WriteTo

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