email

package
v0.0.0-...-b48d978 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2013 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Gone-lib email "one" liners. See func Send() for how to quickly send an email.

Index

Examples

Constants

View Source
const CRLF = "\r\n"

Message header separator.

Variables

This section is empty.

Functions

func Send

func Send(host, username, password, from, to, subject, body string) error

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

func SendPlain(host, username, password, from, to, subject, body string) error

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

type Connection struct {
	Username string
	Password string
	Host     string
}

Email server connection details.

func (*Connection) Send

func (conn *Connection) Send(message *Message, format string) error

Send byte message using format.

type Message

type Message struct {
	From    *mail.Address
	To      *AddressList
	Subject string
	Body    string
}

Email message.

func NewMessage

func NewMessage(from, to, subject, body string) *Message

Create a new email message, assuming no errors.

func NewMessageDebug

func NewMessageDebug(from, to, subject, body string) (*Message, error)

Create a new email message, returning any reasons for failure.

func (*Message) HTMLString

func (message *Message) HTMLString() string

Convert email message to html message format, return as string.

func (*Message) PlainString

func (message *Message) PlainString() string

Convert email message to plain text message format, return as string.

func (*Message) ToBytes

func (message *Message) ToBytes(format string) []byte

Convert email message to a given format in byte form, which is needed by stmp.SendMail(). Supports either "plain" or "html".

Jump to

Keyboard shortcuts

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