mail

package
v0.28.0 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2016 License: AGPL-3.0 Imports: 18 Imported by: 0

Documentation

Overview

Package mail sends transactional emails. The code in smtp.go is designed to provide an "email interface for humans". Designed to be robust and flexible, the email package aims to make sending email easy without getting in the way.

Index

Constants

View Source
const (
	// MaxLineLength is the maximum line length per RFC 2045
	MaxLineLength = 76
)

Variables

View Source
var SMTPCreds = struct{ SMTPuserid, SMTPpassword, SMTPhost, SMTPport, SMTPsender func() string }{
	func() string { return request.ConfigString("SMTP", "userid") },
	func() string { return request.ConfigString("SMTP", "password") },
	func() string { return request.ConfigString("SMTP", "host") },
	func() string {
		r := request.ConfigString("SMTP", "port")
		if r == "" {
			return "587"
		}
		return r
	},
	func() string { return request.ConfigString("SMTP", "sender") },
}

SMTPCreds return SMTP configuration.

Functions

func GetAuth

func GetAuth() smtp.Auth

GetAuth to return SMTP credentials

func GetHost

func GetHost() string

GetHost to return SMTP host details

func InviteExistingUser

func InviteExistingUser(recipient, inviter, url string)

InviteExistingUser invites a known user to an organization.

func InviteNewUser

func InviteNewUser(recipient, inviter, url, username, password string)

InviteNewUser invites someone new providing credentials, explaining the product and stating who is inviting them.

func PasswordReset

func PasswordReset(recipient, url string)

PasswordReset sends a reset email with an embedded token.

func ShareFolderExistingUser

func ShareFolderExistingUser(recipient, inviter, url, folder, intro string)

ShareFolderExistingUser provides an existing user with a link to a newly shared folder.

func ShareFolderNewUser

func ShareFolderNewUser(recipient, inviter, url, folder, invitationMessage string)

ShareFolderNewUser invites new user providing credentials, explaining the product and stating who is inviting them.

Types

type Attachment

type Attachment struct {
	Filename string
	Header   textproto.MIMEHeader
	Content  []byte
}

Attachment is a struct representing an email attachment. Based on the mime/multipart.FileHeader struct, Attachment contains the name, MIMEHeader, and content of the attachment in question

type Email

type Email struct {
	From        string
	To          []string
	Bcc         []string
	Cc          []string
	Subject     string
	Text        []byte // Plaintext message (optional)
	HTML        []byte // Html message (optional)
	Headers     textproto.MIMEHeader
	Attachments []*Attachment
	ReadReceipt []string
}

Email is the type used for email messages

func NewEmail

func NewEmail() *Email

NewEmail creates an Email, and returns the pointer to it.

func (*Email) Attach

func (e *Email) Attach(r io.Reader, filename string, c string) (a *Attachment, err error)

Attach is used to attach content from an io.Reader to the email. Required parameters include an io.Reader, the desired filename for the attachment, and the Content-Type The function will return the created Attachment for reference, as well as nil for the error, if successful.

func (*Email) AttachFile

func (e *Email) AttachFile(filename string) (a *Attachment, err error)

AttachFile is used to attach content to the email. It attempts to open the file referenced by filename and, if successful, creates an Attachment. This Attachment is then appended to the slice of Email.Attachments. The function will then return the Attachment for reference, as well as nil for the error, if successful.

func (*Email) Bytes

func (e *Email) Bytes() ([]byte, error)

Bytes converts the Email object to a []byte representation, including all needed MIMEHeaders, boundaries, etc.

func (*Email) Send

func (e *Email) Send(addr string, a smtp.Auth) error

Send an email using the given host and SMTP auth (optional), returns any error thrown by smtp.SendMail This function merges the To, Cc, and Bcc fields and calls the smtp.SendMail function using the Email.Bytes() output as the message

Jump to

Keyboard shortcuts

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