- Send emails via AWS SES
- Fetch attachments locally, from an S3 Bucket or via HTTP
- Supports both text/plain and text/html emails
package main
import (
"context"
email "github.com/gofor-little/aws-email"
)
func main() {
// Initialize the email package.
if err := email.Initialize("AWS_PROFILE", "AWS_REGION"); err != nil {
panic(err)
}
// Build the email data.
data := email.Data{
To: []string{"[email protected]"},
From: "[email protected]",
Subject: "Example Email",
Body: "Example Body",
ContentType: email.ContentTypeTextPlain,
Attachments: []email.Attachment{
{
Path: "/home/ubuntu/app/logo.png",
Type: email.AttachmentTypeLocal,
},
{
Path: "bucket-name/images/logo.png",
Type: email.AttachmentTypeS3,
},
{
Path: "https://example.com/logo.png",
Type: email.AttachmentTypeHTTP,
},
},
}
// Send the email.
if _, err := email.Send(context.Background(), data); err != nil {
panic(err)
}
}
Ensure the following environment variables are set, usually with a .env file.
AWS_PROFILE
(an AWS CLI profile name)AWS_REGION
(a valid AWS region)TEST_EMAIL_FROM
(a valid email address verified in SES)TEST_EMAIL_RECIPIENTS
(a comma separated list of valid email addresses)