Documentation ¶
Overview ¶
Gone-lib email "one" liners. See func Send() for how to quickly send an email.
Index ¶
Examples ¶
Constants ¶
const CRLF = "\r\n"
Message header separator.
Variables ¶
This section is empty.
Functions ¶
func Send ¶
Send new email message. Assumed to be HTML message.
Parameters:
- host - SMTP server, should include port; i.e. "smtp.example.com:25".
- username - SMTP server username.
- password - SMTP server password.
- from - From email; i.e. "alice@example.com" or "Alice Bane <alice@example.com>".
- to - To email(s); i.e. "bob@example.com" or "Bob Cane <bob@example.com>, Cat Doe <cat@xample.com>".
- subject - Subject for the email.
- body - HTML formatted email body; i.e. "<p>Hello</p>".
Example ¶
This example sends a HTML email using "one" line of code using Gmail's SMTP server.
err := Send("smtp.gmail.com:587", "username@gmail.com", "password", "Abe <username@gmail.com>", "bob@gmail.com", "Hello Bob", "<p>Hi Bob</p><p>Long time no see.</p><p>Abe</p>") if err != nil { // Could not send email }
Output:
func SendPlain ¶
Send new plain email message. Same parameters as Send(), however, body is expected to be plain text.
Example ¶
This example sends a plain email using "one" line of code using a random SMTP server.
err := SendPlain("smtp.example.com:25", "username@example.com", "password", "Abe <username@example.com>", "bob@example.com", "Hello Bob", "Hi Bob\n\nLong time no see.\n\nAbe") if err != nil { // Could not send email }
Output:
Types ¶
type AddressList ¶
type AddressList struct {
// contains filtered or unexported fields
}
AddressList type; essentially just an alias for array of Addresses.
func (*AddressList) ToRFCStrings ¶
func (addressList *AddressList) ToRFCStrings() []string
Convert an array of RFC 5322 addresses to RFC 5322 strings; i.e. "Name <email@example.com>".
func (*AddressList) ToStrings ¶
func (addressList *AddressList) ToStrings() []string
Convert an array of RFC 5322 addresses to strings usable as destination emails.
type Connection ¶
Email server connection details.
type Message ¶
type Message struct { From *mail.Address To *AddressList Subject string Body string }
Email message.
func NewMessage ¶
Create a new email message, assuming no errors.
func NewMessageDebug ¶
Create a new email message, returning any reasons for failure.
func (*Message) HTMLString ¶
Convert email message to html message format, return as string.
func (*Message) PlainString ¶
Convert email message to plain text message format, return as string.