Documentation ¶
Index ¶
- Constants
- func SendMessage(from string, recipients []string, msg string, client *SMTPClient) error
- type AuthType
- type ContentType
- type DSN
- type Email
- func (email *Email) AddAddresses(header string, addresses ...string) *Email
- func (email *Email) AddAlternative(contentType ContentType, body string) *Email
- func (email *Email) AddAlternativeData(contentType ContentType, body []byte) *Email
- func (email *Email) AddAttachment(file string, name ...string) *Email
- func (email *Email) AddAttachmentBase64(b64File, name string) *Email
- func (email *Email) AddAttachmentData(data []byte, filename, mimeType string) *Email
- func (email *Email) AddBcc(addresses ...string) *Email
- func (email *Email) AddCc(addresses ...string) *Email
- func (email *Email) AddHeader(header string, values ...string) *Email
- func (email *Email) AddHeaders(headers textproto.MIMEHeader) *Email
- func (email *Email) AddInline(file string, name ...string) *Email
- func (email *Email) AddInlineBase64(b64File, name, mimeType string) *Email
- func (email *Email) AddInlineData(data []byte, filename, mimeType string) *Email
- func (email *Email) AddTo(addresses ...string) *Email
- func (email *Email) Attach(file *File) *Email
- func (email *Email) GetError() error
- func (email *Email) GetFrom() string
- func (email *Email) GetMessage() string
- func (email *Email) GetRecipients() []string
- func (email *Email) Send(client *SMTPClient) error
- func (email *Email) SendEnvelopeFrom(from string, client *SMTPClient) error
- func (email *Email) SetBody(contentType ContentType, body string) *Email
- func (email *Email) SetBodyData(contentType ContentType, body []byte) *Email
- func (email *Email) SetDSN(dsn []DSN, preserveOriginalRecipient bool) *Email
- func (email *Email) SetDate(dateTime string) *Email
- func (email *Email) SetDkim(options dkim.SigOptions) *Email
- func (email *Email) SetFrom(address string) *Email
- func (email *Email) SetListUnsubscribe(address string) *Email
- func (email *Email) SetPriority(priority Priority) *Email
- func (email *Email) SetReplyTo(address string) *Email
- func (email *Email) SetReturnPath(address string) *Email
- func (email *Email) SetSender(address string) *Email
- func (email *Email) SetSubject(subject string) *Email
- type Encryption
- type File
- type Priority
- type SMTPClient
- type SMTPServer
Constants ¶
const ( // EncodingNone turns off encoding on the message body EncodingNone encoding = iota // EncodingBase64 sets the message body encoding to base64 EncodingBase64 // EncodingQuotedPrintable sets the message body encoding to quoted-printable EncodingQuotedPrintable )
Variables ¶
This section is empty.
Functions ¶
func SendMessage ¶ added in v2.8.0
func SendMessage(from string, recipients []string, msg string, client *SMTPClient) error
SendMessage sends a message (a RFC822 formatted message) 'from' must be an email address, recipients must be a slice of email address
Types ¶
type AuthType ¶ added in v2.10.0
type AuthType int
const ( // AuthPlain implements the PLAIN authentication AuthPlain AuthType = iota // AuthLogin implements the LOGIN authentication AuthLogin // AuthCRAMMD5 implements the CRAM-MD5 authentication AuthCRAMMD5 // AuthNone for SMTP servers without authentication AuthNone // AuthAuto (default) use the first AuthType of the list of returned types supported by SMTP AuthAuto )
type ContentType ¶ added in v2.12.0
type ContentType int
const ( // TextPlain sets body type to text/plain in message body TextPlain ContentType = iota // TextHTML sets body type to text/html in message body TextHTML // TextCalendar sets body type to text/calendar in message body TextCalendar // TextAMP sets body type to text/x-amp-html in message body TextAMP )
type DSN ¶ added in v2.16.0
type DSN int
DSN notifications
- 'NEVER' under no circumstances a DSN must be returned to the sender. If you use NEVER all other notifications will be ignored.
- 'SUCCESS' will notify you when your mail has arrived at its destination.
- 'FAILURE' will arrive if an error occurred during delivery.
- 'DELAY' will notify you if there is an unusual delay in delivery, but the actual delivery's outcome (success or failure) is not yet decided.
see https://tools.ietf.org/html/rfc3461 See section 4.1 for more information about NOTIFY
type Email ¶
type Email struct { Charset string Encoding encoding Error error SMTPServer *smtpClient DkimMsg string AllowDuplicateAddress bool AddBccToHeader bool // contains filtered or unexported fields }
Email represents an email message.
func NewMSG ¶
func NewMSG() *Email
NewMSG creates a new email. It uses UTF-8 by default. All charsets: http://webcheatsheet.com/HTML/character_sets_list.php
func (*Email) AddAddresses ¶
AddAddresses allows you to add addresses to the specified address header.
func (*Email) AddAlternative ¶
func (email *Email) AddAlternative(contentType ContentType, body string) *Email
AddAlternative allows you to add alternative parts to the body of the email message. This is most commonly used to add an html version in addition to a plain text version that was already added with SetBody.
func (*Email) AddAlternativeData ¶ added in v2.11.0
func (email *Email) AddAlternativeData(contentType ContentType, body []byte) *Email
AddAlternativeData allows you to add alternative parts to the body of the email message. This is most commonly used to add an html version in addition to a plain text version that was already added with SetBody.
func (*Email) AddAttachment ¶
AddAttachment. DEPRECATED. Use Attach method. Allows you to add an attachment to the email message. You can optionally provide a different name for the file.
func (*Email) AddAttachmentBase64 ¶
AddAttachmentBase64. DEPRECATED. Use Attach method. Allows you to add an attachment in base64 to the email message. You need provide a name for the file.
func (*Email) AddAttachmentData ¶ added in v2.6.0
AddAttachmentData. DEPRECATED. Use Attach method. Allows you to add an in-memory attachment to the email message.
func (*Email) AddBcc ¶
AddBcc adds a Bcc address. You can provide multiple addresses at the same time.
func (*Email) AddHeaders ¶
func (email *Email) AddHeaders(headers textproto.MIMEHeader) *Email
AddHeaders is used to add multiple headers at once
func (*Email) AddInline ¶
AddInline. DEPRECATED. Use Attach method. Allows you to add an inline attachment to the email message. You can optionally provide a different name for the file.
func (*Email) AddInlineBase64 ¶ added in v2.9.0
AddInlineBase64. DEPRECATED. Use Attach method. Allows you to add an inline in-memory base64 encoded attachment to the email message. You need provide a name for the file. If mimeType is an empty string, attachment mime type will be deduced from the file name extension and defaults to application/octet-stream.
func (*Email) AddInlineData ¶ added in v2.6.0
AddInlineData. DEPRECATED. Use Attach method. Allows you to add an inline in-memory attachment to the email message.
func (*Email) Attach ¶ added in v2.9.0
Attach allows you to add an attachment to the email message. The attachment can be inlined
func (*Email) GetMessage ¶
GetMessage builds and returns the email message (RFC822 formatted message)
func (*Email) GetRecipients ¶ added in v2.8.0
GetRecipients returns a slice of recipients emails
func (*Email) Send ¶
func (email *Email) Send(client *SMTPClient) error
Send sends the composed email
func (*Email) SendEnvelopeFrom ¶ added in v2.7.0
func (email *Email) SendEnvelopeFrom(from string, client *SMTPClient) error
SendEnvelopeFrom sends the composed email with envelope sender. 'from' must be an email address.
func (*Email) SetBody ¶
func (email *Email) SetBody(contentType ContentType, body string) *Email
SetBody sets the body of the email message.
func (*Email) SetBodyData ¶ added in v2.9.0
func (email *Email) SetBodyData(contentType ContentType, body []byte) *Email
SetBodyData sets the body of the email message from []byte
func (*Email) SetDSN ¶ added in v2.16.0
SetDSN sets the delivery status notification list, only is set when SMTP server supports DSN extension
To preserve the original recipient of an email message, for example, if it is forwarded to another address, set preserveOriginalRecipient to true
func (*Email) SetDate ¶
SetDate sets the date header to the provided date/time. The format of the string should be YYYY-MM-DD HH:MM:SS Time Zone.
Example: SetDate("2015-04-28 10:32:00 CDT")
func (*Email) SetDkim ¶ added in v2.11.0
SetDkim adds DomainKey signature to the email message (header+body)
func (*Email) SetListUnsubscribe ¶ added in v2.11.0
SetListUnsubscribe sets the Unsubscribe address.
func (*Email) SetPriority ¶
SetPriority sets the email message Priority. Use with either "High" or "Low".
func (*Email) SetReplyTo ¶
SetReplyTo sets the Reply-To address.
func (*Email) SetReturnPath ¶
SetReturnPath sets the Return-Path address. This is most often used to send bounced emails to a different email address.
func (*Email) SetSubject ¶
SetSubject sets the subject of the email message.
type Encryption ¶ added in v2.8.0
type Encryption int
Encryption type to enum encryption types (None, SSL/TLS, STARTTLS)
const ( // EncryptionNone uses no encryption when sending email EncryptionNone Encryption = iota // EncryptionSSL: DEPRECATED. Use EncryptionSSLTLS. Sets encryption type to SSL/TLS when sending email EncryptionSSL // EncryptionTLS: DEPRECATED. Use EncryptionSTARTTLS. sets encryption type to STARTTLS when sending email EncryptionTLS // EncryptionSSLTLS sets encryption type to SSL/TLS when sending email EncryptionSSLTLS // EncryptionSTARTTLS sets encryption type to STARTTLS when sending email EncryptionSTARTTLS )
func (Encryption) String ¶ added in v2.8.0
func (encryption Encryption) String() string
type File ¶ added in v2.9.0
type File struct { // FilePath is the path of the file to attach. FilePath string // Name is the name of file in attachment. Required for Data and B64Data. Optional for FilePath. Name string // MimeType of attachment. If empty then is obtained from Name (if not empty) or FilePath. If cannot obtained, application/octet-stream is set. MimeType string // B64Data is the base64 string to attach. B64Data string // Data is the []byte of file to attach. Data []byte // Inline defines if attachment is inline or not. Inline bool }
File represents the file that can be added to the email message. You can add attachment from file in path, from base64 string or from []byte. You can define if attachment is inline or not. Only one, Data, B64Data or FilePath is supported. If multiple are set, then the first in that order is used.
type SMTPClient ¶
type SMTPClient struct { Client *smtpClient SendTimeout time.Duration KeepAlive bool // contains filtered or unexported fields }
SMTPClient represents a SMTP Client for send email
func (*SMTPClient) Noop ¶
func (smtpClient *SMTPClient) Noop() error
Noop send NOOP command to smtp client
func (*SMTPClient) Quit ¶
func (smtpClient *SMTPClient) Quit() error
Quit send QUIT command to smtp client
func (*SMTPClient) Reset ¶
func (smtpClient *SMTPClient) Reset() error
Reset send RSET command to smtp client
type SMTPServer ¶
type SMTPServer struct { Authentication AuthType Encryption Encryption Username string Password string Helo string ConnectTimeout time.Duration SendTimeout time.Duration Host string Port int KeepAlive bool TLSConfig *tls.Config // use custom dialer CustomConn net.Conn }
SMTPServer represents a SMTP Server If authentication is CRAM-MD5 then the Password is the Secret
func NewSMTPClient ¶
func NewSMTPClient() *SMTPServer
NewSMTPClient returns the client for send email
func (*SMTPServer) Connect ¶
func (server *SMTPServer) Connect() (*SMTPClient, error)
Connect returns the smtp client
func (*SMTPServer) GetEncryptionType ¶ added in v2.8.0
func (server *SMTPServer) GetEncryptionType() Encryption
GetEncryptionType returns the encryption type used to connect to SMTP server