mail

package module
v0.0.0-...-9219eeb Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2013 License: MIT Imports: 13 Imported by: 0

README

Email utilities including RFC5322 messages and Google Mail defaults.

This package is a merge between:
Erik Unger go-mail package github.com/ungerik/go-mail ed957872758630d680d012c923e445dd0a6b80bb
Scott Lawrence go-mail package github.com/bytbox/go-mail a6e25cbc346c474f58896ce882effdc4d9c386c1

bytbox's package contains go structures and a parser from raw arrays of bytes
to these structures. It is like a complete mail receiver.
ungerik's package contains simpler structures and a smtp configuration. It
is like a mail writer.

This package merges the two packages an adds:
- a "reverse-parser", that is a function to convert bytbox Message to a buffer
- more smtp flexibility to send HTML message

Be warned that it is a work in progress.

See `go doc` for more information

Documentation

Overview

Package mail implements a parser for electronic mail messages as specified in RFC5322.

We allow both CRLF and LF to be used in the input, possibly mixed.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseDate

func ParseDate(s string) time.Time

returns a date. Returns Now() if the format is not recognized.

Types

type Address

type Address interface {
	String() string
	Name() string
}

interface to deal with an email address

func ParseAddress

func ParseAddress(bs []byte) (Address, error)

converts an array of bytes into an Address

type GroupAddr

type GroupAddr struct {
	// contains filtered or unexported fields
}

structure containing a list of recipients

func (GroupAddr) Name

func (ga GroupAddr) Name() string

returns the name of the list (eg "Modern TV Sale")

func (GroupAddr) String

func (ga GroupAddr) String() string

returns an empty string, structure must be iterated to retrieve addresses

type Header struct {
	Key, Value string
}

structure containing a header value (respecting RFC5322 or not)

type HeaderInfo

type HeaderInfo struct {
	FullHeaders []Header // all headers
	OptHeaders  []Header // unprocessed headers

	MessageId   string
	Id          string
	Date        time.Time
	From        []Address
	Sender      Address
	ReplyTo     []Address
	To          []Address
	Cc          []Address
	Bcc         []Address
	Subject     string
	Comments    []string
	Keywords    []string
	ContentType string

	InReply    []string
	References []string
}

structure containing the header vars as defined in RFC5322

type MailboxAddr

type MailboxAddr struct {
	// contains filtered or unexported fields
}

structure containing the email address parts

func (MailboxAddr) Name

func (ma MailboxAddr) Name() string

returns a raw email address (eg "bruno.bluthgeld@mydomain.com")

func (MailboxAddr) String

func (ma MailboxAddr) String() string

returns a complete email address (eg "Dr. Bloodmoney <bruno.bluthgeld@mydomain.com>")

type Message

type Message struct {
	HeaderInfo

	Text  string
	Body  []byte
	Parts []Part
}

structure containing a multipart message

func NewHTMLMessage

func NewHTMLMessage(subject, content, from string, to ...string) (*Message, error)

returns a message with minimum headers and html content

func NewTextMessage

func NewTextMessage(subject, content, from string, to ...string) (*Message, error)

returns a message with minimum headers and textual content

func Parse

func Parse(s []byte) (m Message, e error)

converts an array of bytes into a Message structure Successively calls ParseRaw() and Process()

func Process

func Process(r RawMessage) (m Message, e error)

converts a RawMessage into a Message structure

func (*Message) Buffer

func (m *Message) Buffer() (*bytes.Buffer, error)

converts a message to a buffer for SMTP sending

func (*Message) Validate

func (m *Message) Validate() error

checks minimum requirements before trying to send a message

type Part

type Part struct {
	Type    string
	Data    []byte
	Headers map[string][]string
}

structure containing a part of a multipart message

type RawHeader

type RawHeader struct {
	Key, Value []byte
}

structure containing a raw header

type RawMessage

type RawMessage struct {
	RawHeaders []RawHeader
	Body       []byte
}

structure containing a raw message (arrays of bytes)

func ParseRaw

func ParseRaw(s []byte) (m RawMessage, e error)

converts an array of bytes into a RawMessage structure

type SMTPServer

type SMTPServer struct {
	Host     string
	Port     uint16
	Username string
	Password string
	From     Address
	Auth     *smtp.Auth
}

structure to connect to a SMTP server

func InitGmail

func InitGmail(fromAddress, loginAddress, password string) (*SMTPServer, error)

returns a server to a gmail account uses a different fromAddress for sending emails than the loginAddress used together with the password for authentication The fromAddress has to be verified as a valid sender address in Gmail.

func InitLocalHost

func InitLocalHost(fromAddress string) (*SMTPServer, error)

returns the simplest possible server (localhost:25)

func (*SMTPServer) Close

func (self *SMTPServer) Close() error

func (*SMTPServer) Name

func (self *SMTPServer) Name() string

func (*SMTPServer) Send

func (server *SMTPServer) Send(m *Message) error

sends a message via the SMTP server

type SMTPWriter

type SMTPWriter struct {
	io.Writer
	// contains filtered or unexported fields
}

implements io.Writer interface to use template.ExecuteTemplate()

Example:

	 body := new(mail.SMTPWriter)

	 templates.ExecuteTemplate(body, "account_validation", boutique)

  message, err := mail.NewHTMLMessage(subject, body.String(), from, to)
  mailer.Send(message)

func (*SMTPWriter) String

func (self *SMTPWriter) String() string

func (*SMTPWriter) Write

func (self *SMTPWriter) Write(p []byte) (n int, err error)

simply store to []string

Jump to

Keyboard shortcuts

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