gophermail

package module
v0.0.0-...-62941ea Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2016 License: MIT Imports: 14 Imported by: 15

README

gophermail

gophermail is a simple package for sending mail using net/smtp. Something that the core sorely lacks.

View API documentation on GoDoc

Join us on Slack to chat with other gophermail developers! (Request an invite, then join the #gophermail channel.)

Using

Install the package with:

go get gopkg.in/jpoehls/gophermail.v0

Import it with:

import "gopkg.in/jpoehls/gophermail.v0"

and use gophermail as the package name inside the code.

Credits

The API is heavily inspired by the code.google.com/p/appengine-go/appengine/mail package.

Documentation

Overview

gophermail is a simple package for sending mail using net/smtp.

Features:

  • Providing both plain text and HTML message bodies
  • Attachments with data fed from an io.Reader
  • Reply-To header
  • To, Cc, and Bcc recipients

Known Issues: https://github.com/jpoehls/gophermail/issues

Index

Constants

This section is empty.

Variables

View Source
var ErrMissingFromAddress = errors.New("No from address specified.")
View Source
var ErrMissingRecipient = errors.New("No recipient specified. At least one To, Cc, or Bcc recipient is required.")

Functions

func NewBase64MimeEncoder

func NewBase64MimeEncoder(w io.Writer) io.WriteCloser

func SendMail

func SendMail(addr string, a smtp.Auth, msg *Message) error

SendMail connects to the server at addr, switches to TLS if possible, authenticates with mechanism a if possible, and then sends the given Message.

Based heavily on smtp.SendMail().

func SendTLSMail

func SendTLSMail(addr string, a smtp.Auth, msg *Message, cfg tls.Config) error

SendTLSMail does the same thing as SendMail, except with the added option of providing a tls.Config

Types

type Attachment

type Attachment struct {
	// Name must be set to a valid file name.
	Name string

	// Optional.
	// Uses mime.TypeByExtension and falls back
	// to application/octet-stream if unknown.
	ContentType string

	Data io.Reader
}

An Attachment represents an email attachment.

type Message

type Message struct {

	// Technically this could be a list of addresses but we don't support that. See RFC 2822 s3.6.2.
	From mail.Address

	// Technically this could be a list of addresses but we don't support that. See RFC 2822 s3.6.2.
	ReplyTo mail.Address // optional

	To, Cc, Bcc []mail.Address

	Subject string // optional

	Body     string // optional
	HTMLBody string // optional

	Attachments []Attachment // optional

	// Extra mail headers.
	Headers mail.Header
}

A Message represents an email message. Addresses may be of any form permitted by RFC 5322.

func (*Message) AddBcc

func (m *Message) AddBcc(addresses ...string) error

AddBcc creates a mail.Address and adds it to the list of Bcc addresses in the message

func (*Message) AddCc

func (m *Message) AddCc(addresses ...string) error

AddCc creates a mail.Address and adds it to the list of Cc addresses in the message

func (*Message) AddTo

func (m *Message) AddTo(addresses ...string) error

AddTo creates a mail.Address and adds it to the list of To addresses in the message

func (*Message) Bytes

func (m *Message) Bytes() ([]byte, error)

Bytes gets the encoded MIME message.

func (*Message) SetFrom

func (m *Message) SetFrom(address string) error

SetFrom creates a mail.Address and assigns it to the message's From field.

func (*Message) SetReplyTo

func (m *Message) SetReplyTo(address string) error

SetReplyTo creates a mail.Address and assigns it to the message's ReplyTo field.

Jump to

Keyboard shortcuts

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