gomail

package
v0.0.0-...-29068ce Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2014 License: MIT Imports: 13 Imported by: 2

Documentation

Overview

Deprecated, use https://github.com/go-gomail/gomail instead. Package gomail provides a simple interface to easily write and send emails.

Example:

package main

import (
	"log"

	"github.com/alexcesaro/mail/gomail"
)

func main() {
	msg := gomail.NewMessage()
	msg.SetAddressHeader("From", "alex@example.com", "Alex")
	msg.SetHeader("To", "bob@example.com")
	msg.AddHeader("To", "cora@example.com")
	msg.SetHeader("Subject", "Hello!")
	msg.SetBody("text/plain", "Hello Bob and Cora!")
	msg.AddAlternative("text/html", "Hello <b>Bob</b> and <i>Cora</i>!")
	if err := msg.Attach("/home/Alex/lolcat.jpg") {
		log.Println(err)
		return
	}

	m := gomail.NewMailer("smtp.example.com", "user", "123456", 25)
	if err := m.Send(msg); err != nil { // This will send the email to Bob and Cora
		log.Println(err)
	}
}

Index

Constants

View Source
const (
	// QuotedPrintable represents the quoted-printable encoding as defined in
	// RFC 2045.
	QuotedPrintable = "quoted-printable"
	// Base64 represents the base64 encoding as defined in RFC 2045.
	Base64 = "base64"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Mailer

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

A Mailer represents an SMTP server.

func NewCustomMailer

func NewCustomMailer(auth smtp.Auth, addr string) Mailer

NewCustomMailer creates a mailer using any authentication mechanism.

func NewMailer

func NewMailer(host string, username string, password string, port int) Mailer

NewMailer returns a mailer. The given parameters are used to connect to the SMTP server via a PLAIN authentication mechanism.

func (Mailer) Send

func (m Mailer) Send(message *Message) error

Send sends the emails to the recipients of the message.

type Message

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

Message represents a mail message.

func NewCustomMessage

func NewCustomMessage(charset, encoding string) *Message

NewCustomMessage creates a new message that will use the given encoding and charset.

func NewMessage

func NewMessage() *Message

NewMessage creates a new UTF-8 message using quoted-printable encoding.

func (*Message) AddAddressHeader

func (msg *Message) AddAddressHeader(field, address, name string)

AddAddressHeader adds an address to the given header field.

func (*Message) AddAlternative

func (msg *Message) AddAlternative(contentType, body string)

AddAlternative adds an alternative body to the message. Usually used to provide both an HTML and a text version of the message.

func (*Message) AddDateHeader

func (msg *Message) AddDateHeader(field string, date time.Time)

AddDateHeader adds a date to the given header field.

func (*Message) AddHeader

func (msg *Message) AddHeader(field, value string)

AddHeader adds a value to the given header field.

func (*Message) Attach

func (msg *Message) Attach(filename string) error

Attach attaches a file to the message.

func (*Message) DelHeader

func (msg *Message) DelHeader(field string)

DelHeader deletes a header field.

func (*Message) Export

func (msg *Message) Export() (*mail.Message, error)

Export converts the message into a net/mail.Message.

func (*Message) GetBodyWriter

func (msg *Message) GetBodyWriter(contentType string) io.Writer

GetBodyWriter gets a writer that writes to the body. It can be useful with the templates from packages text/template or html/template.

Example:

w := msg.GetBodyWriter("text/plain")
t := template.Must(template.New("example").Parse("Hello {{.}}!"))
t.Execute(w, "Bob")

func (*Message) GetHeader

func (msg *Message) GetHeader(field string) []string

GetHeader gets a header field.

func (*Message) SetAddressHeader

func (msg *Message) SetAddressHeader(field, address, name string)

SetAddressHeader sets an address to the given header field.

func (*Message) SetBody

func (msg *Message) SetBody(contentType, body string)

SetBody sets the body of the message.

func (*Message) SetDateHeader

func (msg *Message) SetDateHeader(field string, date time.Time)

SetDateHeader sets a date to the given header field.

func (*Message) SetHeader

func (msg *Message) SetHeader(field, value string)

SetHeader sets a value to the given header field.

Jump to

Keyboard shortcuts

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