Skip to content

Go package to implement the `gomail.Sender` interface using the AWS Simple Email Service (SES).

License

Notifications You must be signed in to change notification settings

aaronland/gomail-sender-ses

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gomail-sender-ses

<<<<<<< HEAD Go package to implement the gomail.Sender interface using the AWS Simple Email Service (SES).

Documentation

Go Reference

Go package to implement the gomail.Sender interface using the AWS Simple Email Service (sesv2).

Documentation

Documentation is incomplete.

07006fef2d07036f0ea3fccd9d63e496fad95c73

Example

<<<<<<< HEAD
package main

import (
	_ "github.com/aaronland/gomail-sender-ses"
)

import (
	"github.com/aaronland/gomail-sender"
	"github.com/aaronland/gomail/v2"
	"flag"
	"context"
=======
import(
	"context"
	"fmt"
	"net/url"

	"github.com/aaronland/gomail-sender"
	_ "github.com/aaronland/gomail-sender-ses/v2"	
	"github.com/aaronland/gomail/v2"	
>>>>>>> 07006fef2d07036f0ea3fccd9d63e496fad95c73
)

func main() {

<<<<<<< HEAD
	sender_uri := flag.String("sender-uri", "", "A valid aaronland/gomail-sender URI")
	from := flag.String("from", "", "A valid From: address (that has been registered with SES)")
	to := flag.String("to", "", "A valid To: address")
	subject := flag.String("subject", "", "A valid email subject")		
	
	flag.Parse()
	
	ctx := context.Background()

	mail_sender, _ := sender.NewSender(ctx, *sender_uri)

	msg := gomail.NewMessage()

	msg.SetHeader("Subject", *subject)
	msg.SetHeader("From", *from)
	msg.SetHeader("To", *to)

	msg.SetBody("text/plain", "This message left intentionally blank.")

	gomail.Send(mail_sender, msg)
}

Error handling removed for the sake of brevity.

Tools

$> make cli
go build -mod vendor -o bin/send cmd/send/main.go

send

$> ./bin/send \
	-sender-uri 'ses://?credentials={CREDENTIALS}&region={REGION}'
	-from bob@example.com \
	-to alice@example.com \
	-subject 'This is a test'

Sender URIs

Sender URIs take the form of:

ses://?credentials={CREDENTIALS}&region={REGION}

Where {CREDENTIALS} is a valid aaronland/go-aws-session credentials string and {REGION} is a valid AWS region.

Credentials strings for AWS sessions are defined as string labels. They are:

Label Description
env: Read credentials from AWS defined environment variables.
iam: Assume AWS IAM credentials are in effect.
{AWS_PROFILE_NAME} Use the profile from the default AWS credentials location.
{AWS_CREDENTIALS_PATH}:{AWS_PROFILE_NAME} Use the profile from a user-defined AWS credentials location.

See also


## Credentials

Credentials strings (as `?credentials={CREDENTIALS}`) are expected to be a valid [aaronland/go-aws-auth](https://github.com/aaronland/go-aws-auth?tab=readme-ov-file#credentials) credentials "label":

| Label | Description |
| --- | --- |
| `anon:` | Empty or anonymous credentials. |
| `env:` | Read credentials from AWS defined environment variables. |
| `iam:` | Assume AWS IAM credentials are in effect. |
| `sts:{ARN}` | Assume the role defined by `{ARN}` using STS credentials. |
| `{AWS_PROFILE_NAME}` | This this profile from the default AWS credentials location. |
| `{AWS_CREDENTIALS_PATH}:{AWS_PROFILE_NAME}` | This this profile from a user-defined AWS credentials location. |

For example:

aws:///us-east-1?credentials=iam:


## See also

* https://pkg.go.dev/github.com/aws/aws-sdk-go-v2/service/sesv2
* https://github.com/aaronland/gomail-sender
* https://github.com/aaronland/gomail/v2
* https://github.com/aaronland/go-aws-auth
>>>>>>> 07006fef2d07036f0ea3fccd9d63e496fad95c73

About

Go package to implement the `gomail.Sender` interface using the AWS Simple Email Service (SES).

Resources

License

Stars

Watchers

Forks

Packages

No packages published