mail-worker is a robust Cloudflare Worker built for sending emails with AWS SES using SES API v2.
POST / (send email to recipient(s))
name type description Authorization optional AUTH_TOKENenvironment variable
name type data type description from required stringsender's email address to required string[]recipient's email address(es) cc optional string[]cc recipient's email address bcc optional string[]bcc recipient's email address subject optional stringemail subject html optional stringemail content attachments optional Attachment[]email attachments
name type data type description name optional stringname of the attachment content required base64base64-encoded content of the attachment type required stringMIME type of the attachment
http code content-type reason 200text/plainemail sent successfully 400text/plaininvalid request body 401text/plaininvalid authentication token 500text/plainAWS SES is unavailable/setup incorrectly or the sender is unverified
curl $MAIL_WORKER_ENDPOINT -H "Content-Type: application/json" -d \ '{ "to": ["test@test.com"], "from": "test@test.com", "subject": "test", "html": "test" }'
curl $MAIL_WORKER_ENDPOINT -H "Content-Type: application/json" -d \ '{ "to": ["test@test.com"], "from": "test@test.com", "subject": "test", "html": "test", "attachments": [{"name": "text.txt", "type": "text/plain", "content": "SGVsbG8gV29ybGQ="}] }'
curl $MAIL_WORKER_ENDPOINT \ -H "Authorization: $AUTH_TOKEN" \ -H "Content-Type: application/json" -d \ '{ "to": ["test@test.com"], "from": "test@test.com", "subject": "test", "html": "test" }'
Your worker must have the following environment variables.
echo $AWS_REGION | npx wrangler secret put AWS_REGION
echo $AWS_ACCESS_KEY_ID | npx wrangler secret put AWS_ACCESS_KEY_ID
echo $AWS_SECRET_ACCESS_KEY | npx wrangler secret put AWS_SECRET_ACCESS_KEYOptionally, you may secure your endpoint by setting the following environment variable.
echo $AUTH_TOKEN | npx wrangler secret put AUTH_TOKENTo use any sender email, the email must first be verified. The verification will require the following environment variables. You may populate your environment with the following.
{
echo "AWS_REGION=$AWS_REGION"
echo "AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID"
echo "AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY"
} > .envNow, pipe your email to the verify-email script.
echo $EMAIL_ADDRESS | bun verify-emailInstall all dependencies.
bun install