A mail worker built with Cloudflare Workers and AWS SES.
mail-worker
is a robust Cloudflare Worker built for sending emails with AWS SES and Bun.
Install all dependencies.
bun install
POST
/
(send email to recipient(s))
name type description Authorization optional AUTH_TOKEN
environment variable
name type data type description to required string[]
recipient's email address(es) from required string
sender's email address subject required string
email subject html required string
email content
http code content-type response 200
text/plain
Email sent!
400
text/plain
Invalid request!
401
text/plain
Unauthorised! Please check your token in the request.
500
text/plain
Failed to send email!
curl $MAIL_WORKER_ENDPOINT -H "Content-Type: application/json" -d \ '{ "to": ["[email protected]"], "from": "[email protected]", "subject": "test", "html": "test" }'
curl $MAIL_WORKER_ENDPOINT \ -H "Authorization: $AUTH_TOKEN" \ -H "Content-Type: application/json" -d \ '{ "to": ["[email protected]"], "from": "[email protected]", "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_KEY
Optionally, you may secure your endpoint by setting the following environment variable.
echo $AUTH_TOKEN | npx wrangler secret put AUTH_TOKEN
To 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"
} >> .env
Now, pipe your email to the verify-email
script.
echo $EMAIL_ADDRESS | bun verify-email