# README
email for Go
A basic wrapper for Amazon SES, Mailgun and Sendgrid APIs
Installation
go get -u github.com/8o8/email
Tests Require Env Vars
To run the tests set up a .env
file with the following values:
Don't forget to add
.env
to.gitignore
. If you accidentally push the.env
file to a public repo, the keys will be detected, alarms will ring and Mailgun/Sendgrid will immediately suspend your account.
# For Amazon SES - also need IAM, Policy and all that guff
AWS_REGION="amazon-ses-region"
AWS_ACCESS_KEY_ID="your-amazon-access-key-id"
AWS_SECRET_ACCESS_KEY="your-amazon-secret-access-key"
# Mailgun is easier
MAILGUN_DOMAIN="your.mailgun.domain"
MAILGUN_API_KEY="your-mailgun-api-key"
# Sengrid, easier again
SENDGRID_API_KEY="your-sendgrid-api-key"
# If Amazon SES account is still in sandbox mode, these email addresses will
# need to be verified before they will work
TEST_SENDER_NAME="8o8 Test Mail"
TEST_SENDER_EMAIL="[email protected]"
TEST_RECIPIENT_NAME="Your Name"
TEST_RECIPIENT_EMAIL="[email protected]"
# Skip test for any value other than "true"
TEST_MAILGUN="true"
TEST_SENDGRID="" # false
TEST_SES=true="" # false
Usage
package main
import "github.com/8o8/email"
func main() {
em := email.Email{
FromName: "Send Name",
FromEmail: "[email protected]",
ToName: "Recipient Name",
ToEmail: "[email protected]",
Subject: "The Subject",
PlainContent: "This is the plain text",
HTMLContent: "<h1>This is HTML</h1>",
}
// cfg for the specific api
cfg := email.MailgunCfg{
APIKey: apiKey,
Domain: domain,
}
mx := email.NewMailgun(cfg)
err := mx.Send(em)
if err != nil {
fmt.Println(err)
}
}
Versioning
As stated in item 4 of the SemVer specification:
Major version zero (0.y.z) is for initial development. Anything may change at any time. The public API should not be considered stable.
# Functions
NewMailgun returns a pointer to a local Mailgun value.
NewSendgrid returns a pointer to a SendgridEmail.
NewSES returns a pointer to an SES sender.
# Structs
Attachment to an email.
Email represents an email.
Mailgun implements the sender interface.
MailgunCfg defines the configuration for Mailgun.
Sendgrid implements the sender interface.
SendgridCfg defines the configuration for Sendgrid.
SES implements the sender interface.
SESCfg provides config info.