/maildom

Nodejs serverless SMTP email service using AWS Lambda & API Gateway

Primary LanguageJavaScriptGNU Lesser General Public License v2.1LGPL-2.1

coming soon

Markdownify

Build Status Maintainability codecov

A serverless Nodejs SMTP email service using AWS Lambda & API Gateway.

Motivation

When working with Jamstack or static html websites, additional functionality like sending off emails require a server or at least, SaaS.

If all you want is an endpoint that takes a few fields and sends off an email, it's a nice alternative that doesn't require the maintenance of a server.

Is it ready for production?

TLDR, I wish, but no.

You can take it and build on it if you like though.

What still needs doing? Read here

How to use it

Clone this repository and follow the "Get set up" guide.

Pre-requisites

  • Serverless (version ^1.27.3)

  • Node (version 8)

  • NPM

  • AWS Account (with IAM access)

    You will need IAM credentials configured with AWS. You can use serverless to set these up:

    serverless config credentials --provider aws --key XXXXXXX --secret XXXXXXX

    If you have more than 1 set of credentials, you can create a new custom profile the Serverless way.

    serverless config credentials --provider aws --key XXXXXXX --secret XXXXXXX --profile XXXXXXX
  • SMTP Email (Using a fake SMTP email for testing)

Get set up

  • In the serverless.yml
    • Set the service name
    • Change the function name to be more relevant
    • Set your profile name or remove if irrelevant

Testing locally

If you want to get testing with SMTP fast and don't yet have your own credentials, get a fake test email using the Ethereal Email service:

https://ethereal.email/

SMTP_USER=someusername \
SMTP_PASS=somepassword \
SMTP_HOST=smtp.ethereal.email \
SENDER_NAME=Thomas \
SENDER_EMAIL=the@tankengine.com \
node -e 'require("./handler").email({body: "{\"email\": \"123@abc.com\", \"subject\":\"What a wonderful world\", \"content\": \"Two little birds\\r\\nCame to my doorstep\"}"}, {}, () => {})'

Deploying

serverless deploy

Configure environment variables in AWS

Log into AWS

Go into the AWS Lambda panel

Go the deployed function

Add the environment variables

Variabales

SENDER_EMAIL

SENDER_NAME

SMTP_HOST

SMTP_PASS

SMTP_PORT

SMTP_USER

API

{
	"email": "you@you.com",
	"subject": "Maildom",
	"content": "Hi world!\n\rMaildom here"
}

ToDo

  • 100% Code coverage
  • Send query parameters
  • Use AWS Environment variables to set smtp information
  • Unhappy paths especially for nicer error responses
  • Dynamic variables in serverless.yml to make it multi-environment friendly and reusable across multiple projects

Roadmap

  • An easy npm installation of the lambda service
  • Optional re-captcha
  • HTML Email

Credits

License

GPLv2.1

Here's a nice 4 minute explanation of the difference between GPL and the Lesser GPL. This library uses the Lesser GPL.

Author

Gemma Black

Twitter: @GemmaBlackUk