Amazon SES

Version 0.0.1 · Owners: @benallfree

Walkthrough for app owners: Amazon SES bounces and complaints. This page is the technical reference.

Receives Amazon SES's bounce and complaint notifications through an SNS HTTPS subscription, checks each delivery's signature, and raises them as mail.feedback/v1 events. Whatever acts on them (Bulk Mail's suppression list, a CRM, your own hooks) never needs to know they came from SES.

Install · Configure · Use · Integrations · Example

Install

extkit.Setup(app, []extkit.Extension{settings.New(), bulkmail.New(bulkmail.Config{}), ses.New(ses.Config{})}, nil, nil)

A community extension: it isn't in the pocketone binary. Add it to a custom build of an app that sends through SES.

Configure

Settings → Mail settings → Amazon SES (settings/v1):

Setting
SNS endpoint The URL to subscribe (read-only): <API URL>/api/_c/mail.feedback.ses/v1/sns.
Allowed SNS topic ARNs Comma separated. Empty accepts any topic whose deliveries SNS signed.
API URL Where SNS reaches the app, when the Application URL is a site that doesn't.

In AWS:

  1. Create an SNS topic, and in SES set it as the identity's bounce and complaint notification topic.
  2. Turn on Include original headers for those notifications, so events carry the headers the app put on each message (Bulk Mail reads its campaign from them).
  3. Subscribe the SNS endpoint to the topic (HTTPS). The extension confirms the subscription itself.

Config.HTTPClient fetches SNS signing certificates and confirms subscriptions (default: a 10 s timeout).

Use

Each SES notification becomes one event per recipient:

SES Event
Bounce, Permanent bounce, Permanent: true
Bounce, Transient or Undetermined bounce, Permanent: false
Complaint complaint

Source is ses, Time is SES's timestamp, and MessageID and Header(...) are the original message's, when SES includes them. Identity notifications and configuration-set event publishing (eventType) are both read.

Integrations

Extension How they fit
Bulk Mail Turns permanent bounces and complaints into suppressions, credited to the campaign that sent the message.
Settings The settings are a section on Settings → Mail settings.
KV The settings are stored in the key-value store.

Example

// Command example runs one PocketOne app that takes Amazon SES's bounce and complaint notifications and logs each
// mail.feedback/v1 event.
//
//	go run ./example serve
//
// Then, in the dashboard ([email protected] / password): Settings → Mail settings → Amazon SES shows the SNS endpoint to
// subscribe (it has to be reachable from AWS: a tunnel, or set API URL). Add Bulk Mail (ext/bulkmail) to turn the
// events into suppressions.
//
// Logins (ext/devusers, local testing only): dashboard [email protected] / password, app user [email protected] / password.
package main

import (
	"log"

	"ganigeorgiev.com/pocketbase/pocketbase"
	feedbackv1 "pocketone.dev/ext/contracts/mail/feedback/v1"
	"pocketone.dev/ext/devusers"
	"pocketone.dev/ext/extkit"
	"pocketone.dev/ext/ses"
	"pocketone.dev/ext/settings"
)

func main() {
	app := pocketbase.New()
	devusers.Register(app) // local testing: superuser [email protected] and user [email protected], password "password"
	if _, err := extkit.Setup(app, []extkit.Extension{settings.New(), ses.New(ses.Config{})}, nil, nil); err != nil {
		log.Fatal(err)
	}
	feedbackv1.OnEvent(app).BindFunc(func(e *feedbackv1.Event) error {
		app.Logger().Info("mail feedback", "kind", e.Kind, "permanent", e.Permanent, "email", e.Email, "messageId", e.MessageID)
		return e.Next()
	})
	if err := app.Start(); err != nil {
		log.Fatal(err)
	}
}

How it works

The endpoint is the wire contract mail.feedback.ses/v1. A delivery is accepted only when its signature checks out against a certificate fetched over HTTPS from an sns.<region>.amazonaws.com host (cached per URL), and, when topics are set, its topic is one of them. Subscription confirmations are confirmed by fetching their SubscribeURL, which must be an SNS host too.

License

MIT