Skip to content

ClintEsteMadera/email-sending-service

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

E-Mail Sending Service

A tiny REST API to send e-mails.


Microservice for sending emails over a REST API.

Configuration

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]

Start up

Setting up and starting up the app is as simple as running:

yarn install
yarn start

Run tests

yarn test

Usage Examples

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:

API

POST /email

Sends an email.

Arguments:

The request expects a JSON payload in the body of the POST request. The relevant parameters are:

Required:

  • to: The destination email address
  • subject: The re: line
  • text: The body of the email

Optional:

  • from: Originator
  • html: HTML version of the email body. If present, this parameter takes precedence over whatever is conveyed by the text parameter.
  • attachments: one or more attachments. See the interactive documentation for further detail.

Auth

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.

Requirements

  • Node.js 7+

About

Imperva Code Challenge

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published