0.0.0 • Published 1 year ago
dsmailer v0.0.0
mail-worker
mail-worker is a robust Cloudflare Worker built for sending emails with AWS SES and Bun.
Development
Install all dependencies.
bun installUsage
POST / (send email to recipient(s))
Request Headers
name type description Authorization optional AUTH_TOKENenvironment variable
Parameters
name type data type description to required string[]recipient's email address(es) from required stringsender's email address subject required stringemail subject html required stringemail content
Responses
http code content-type response 200text/plainEmail sent!400text/plainInvalid request!401text/plainUnauthorised! Please check your token in the request.500text/plainFailed to send email!
Example cURL
curl $MAIL_WORKER_ENDPOINT -H "Content-Type: application/json" -d \ '{ "to": ["test@test.com"], "from": "test@test.com", "subject": "test", "html": "test" }'
Example cURL with Authentication
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" }'
Setup
Environment
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_KEYAuthentication
Optionally, you may secure your endpoint by setting the following environment variable.
echo $AUTH_TOKEN | npx wrangler secret put AUTH_TOKENVerify Email
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"
} >> .envNow, pipe your email to the verify-email script.
echo $EMAIL_ADDRESS | bun verify-email0.0.0
1 year ago