Help us shape the future of Go! Take the 2026 Go Developer Survey

mail

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2019 License: MIT Imports: 2 Imported by: 0

README

go-mail Build Status GoDoc

Package mail provides an easy interface with interchangable backends. Pull requests for additional mail providers are very welcome.

Implementation roadmap

Example usage

package main

import (
	"github.com/fastbill/go-mail"
	"github.com/fastbill/go-mail/mandrill"
)

func main() {
	// Create and ping Mandrill client
	client := mandrill.MustNew("https://mandrillapp.com/api/1.0/", "my-token")
	err := client.Ping()
	if err != nil {
		panic(err)
	}

	// Send email
	err = client.Send(&mail.Mail{
		From:    &mail.Sender{Name: "FastBill GmbH", Email: "no-reply@fastbill.com"},
		To:      []mail.Recipient{mail.Recipient{Name: "Info", Email: "info@fastbill.com"}},
		Subject: "Hello world",
		HTML:    "<h1>Hello</h1>",
		Text:    "Hello",
		Options: &mandrill.Options{
			Important: true,
		},
	})
	if err != nil {
		panic(err)
	}
}

Documentation

Overview

Package mail provides an easy interface with interchangable backends

Create and ping Mandrill client

client := mandrill.MustNew("https://mandrillapp.com/api/1.0/", "my-token")
err := client.Ping()
if err != nil {
	panic(err)
}

Send email

err = client.Send(&mail.Mail{
	From:    &mail.Sender{Name: "FastBill GmbH", Email: "no-reply@fastbill.com"},
	To:      []mail.Recipient{mail.Recipient{Name: "Info", Email: "info@fastbill.com"}},
	Subject: "Hello world",
	HTML:    "<h1>Hello</h1>",
	Text:    "Hello",
	Options: &mandrill.Options{
		Important: true,
	},
})
if err != nil {
	panic(err)
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client interface {
	// Send sends an email through the client
	Send(*Mail) error
	// Ping the address and validate key
	Ping() error
}

Client can be implemented for various services

type HTTPClient

type HTTPClient interface {
	// Post issues a POST to the specified URL
	Post(url string, contentType string, payload io.Reader) (*http.Response, error)
}

HTTPClient is an interface for just the Post-method of *http.Client for easy mocking

type Mail

type Mail struct {
	// From is the name and email where this email is sent from
	From *Sender
	// To holds one or more recipients
	To []Recipient
	// Subject holds the mail subject
	Subject string
	// Headers are standard mail headers
	Headers map[string]interface{}
	// HTML will be displayed as html in the email
	HTML string
	// Text will be displayed as plain text in the email
	Text string
	// Options can be a custom interface provided by the client implementation
	Options interface{}
}

Mail is a mail you can send

type Recipient

type Recipient struct {
	Name  string
	Email string
}

Recipient is an email/name combination

type Sender

type Sender Recipient

Sender holds data about the sender

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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