Documentation ¶
Overview ¶
Package mail is a simple email sender written in Go. Please refer to the https://github.com/kataras/mail/tree/master/_examples folder for more.
Index ¶
- Constants
- Variables
- func SendUNIX(from *Address, subject string, body []byte, to ...string) error
- type Address
- type Builder
- func (b *Builder) AppendBody(bodyData []byte) *Builder
- func (b *Builder) Body(body []byte) *Builder
- func (b *Builder) BodyReadCloser(r io.ReadCloser) *Builder
- func (b *Builder) BodyReader(r io.Reader) *Builder
- func (b *Builder) BodyString(body string) *Builder
- func (b *Builder) From(name, address string) *Builder
- func (b *Builder) MarkSingleton() *Builder
- func (b *Builder) Send() error
- func (b *Builder) SendUNIX() error
- func (b *Builder) Subject(subject string) *Builder
- func (b *Builder) To(recipients ...string) *Builder
- type Credentials
- type Mail
Constants ¶
const (
// Version current semantic version of the `mail` package.
Version = "0.0.1"
)
Variables ¶
var ParseAddress = mail.ParseAddress
ParseAddress parses a string to an `Address`.
Usage: addr, err := mail.ParseAddress("Gerasimos <gerasimos@example.com>") addr.Name is "Gerasimos" and addr.Address is "gerasimos@example.com".
ParseAddress is just a shortcut of `net/mail#ParseAddress`.
Functions ¶
func SendUNIX ¶
SendUNIX will call the "sendmail" unix command and send the e-mail based on the given subject, body and recipients (to). If the "sendmail" command is not part of the host's(current machine) programs then it will return an error. It resets the current Builder on finish.
Note that this function can be used from a *nux operating system host only, windows operating system doesn't support this. Don't forget to make sure to configure the machine's mail client before make use of this feature.
Types ¶
type Builder ¶
type Builder struct {
// contains filtered or unexported fields
}
Builder is the builder of the e-mail headers and message body, it resets the current Builder instance each time `Send` is called to avoid memory allocations.
See `Mail#Subject`.
func (*Builder) AppendBody ¶
AppendBody adds more body to the body of the mail.
func (*Builder) BodyReadCloser ¶
func (b *Builder) BodyReadCloser(r io.ReadCloser) *Builder
BodyReadCloser same as `BodyReader` but it closes the reader at the end.
func (*Builder) BodyReader ¶
BodyReader same as `Body` but it accepts an io.Reader to read the actual body from and set.
func (*Builder) BodyString ¶
BodyString sets a body like `Body` but it accepts a string instead of []byte.
func (*Builder) From ¶
From is from address header, it's not required. If not setted then the `Mail.DefaultFrom` will be used instead.
Accepts two input arguments: name is the proper name; may be empty. address is the full address; user@domain.
func (*Builder) MarkSingleton ¶
MarkSingleton will make this Builder re-usable, even after the `Send` or `SendUNIX` functions.
func (*Builder) Send ¶
Send sends the e-mail based on the subject, body and recipients. It resets the current Builder on finish.
func (*Builder) SendUNIX ¶
SendUNIX will call the "sendmail" unix command and send the e-mail based on the subject, body and recipients. If the "sendmail" command is not part of the host's(current machine) programs then it will return an error. It resets the current Builder on finish.
Note that this function can be used from a *nux operating system host only, windows operating system doesn't support this. Don't forget to make sure to configure the machine's mail client before make use of this feature.
type Credentials ¶
type Credentials struct { // Addr is the server mail server's full host, IP or host:port, // // if port is missing then `:smtp` will be used. // // Required. Addr string // Username is the auth username@domain.com for the sender. // /// Required. Username string // Password is the auth password for the sender. // // Required. Password string }
Credentials are the SMTP credentials.
type Mail ¶
type Mail struct { Addr string // DefaultFrom is being used if from Address is missing from the // Send functions, it's the "Username <Username@host>". DefaultFrom *Address // Auth is exported so caller can change it to another. // // Defaults to smtp.PlainAuth based on the Credential's Addr, Username and Password. Auth smtp.Auth }
Mail is the main structure of this package, it's the mail sender.
func New ¶
func New(c Credentials) (*Mail, error)
New returns a new Mail instance based on the given `Credentials`.