A tiny REST API to send e-mails.
Microservice for sending emails over a REST API.
The microservice is configured entirely through environment variables:
Required:
AWS_ACCESS_KEY_ID=[aws_access_key]
AWS_SECRET_ACCESS_KEY=[aws_secret_key]
AWS_REGION=[aws_region]
EMAIL_SENDING_SERVICE_WEB_PORT=[web-listening-port]
EMAIL_SENDING_SERVICE_USE_SES=[boolean]
EMAIL_SENDING_SERVICE_MAX_ATTACHMENTS=[number]
EMAIL_SENDING_SERVICE_MAX_ATTACHMENT_SIZE_IN_MB=[number]
Required only when using an SMTP transport:
EMAIL_SENDING_SERVICE_SMTP_HOST=[host]
EMAIL_SENDING_SERVICE_SMTP_PORT=[port]
EMAIL_SENDING_SERVICE_SMTP_SECURE=[boolean]
EMAIL_SENDING_SERVICE_SMTP_USER=[user]
EMAIL_SENDING_SERVICE_SMTP_PASS=[pass]
Setting up and starting up the app is as simple as running:
yarn install
yarn start
yarn test
Sending a simple e-mail without attachments:
curl -X POST "http://localhost:3000/email" -H "accept: application/json" -H "Content-Type: application/json" -d "{ \"from\": \"[email protected]\", \"to\": \"[email protected]\", \"subject\": \"I'm sending e-mails, yo!\", \"text\": \"This is my super important e-mail!\"}"
To send attachments, the service uses a subset of the nodemailer attachments syntax. Example:
curl -X POST "http://localhost:3000/email" -H "accept: application/json" -H "Content-Type: application/json" -d "{ \"from\": \"[email protected]\", \"to\": \"[email protected]\", \"subject\": \"I'm sending e-mails with attachments, yo!\", \"text\": \"See attached file.\", \"attachments\": [ { \"filename\": \"README.md\", \"href\": \"https://raw.githubusercontent.com/ClintEsteMadera/email-sending-service/master/readme.md\", \"contentType\": \"application/text\", \"contentLength\": 2364 } ]}"
Through the interactive API docs (at /api-docs
), you can inspect and run all the requests:
Sends an email.
The request expects a JSON payload in the body of the POST request. The relevant parameters are:
Required:
to:
The destination email addresssubject:
The re: linetext:
The body of the email
Optional:
from:
Originatorhtml:
HTML version of the email body. If present, this parameter takes precedence over whatever is conveyed by thetext
parameter.attachments
: one or more attachments. See the interactive documentation for further detail.
This service defaults to no authentication.
E-Mail Sending Service uses Express. The file middleware.js
at the root of the directory exposes the app so you can add middleware hooks for auth logic.
- Node.js 7+