Home

Awesome

✉️ serverless-mailer

Serverless Service for sending emails. Compatible with Serverless version 1.0.0-rc.2.

Features

Quick Usage

git clone https://github.com/eahefnawy/serverless-mailer
cd serverless-mailer
npm install

Open .env file and set the following env vars:

EMAIL_SERVICE=Gmail
EMAIL_SERVICE_USER=username@gmail.com
EMAIL_SERVICE_PASS=password

NOTE: In case of Gmail, you need to setup an "App Password"

Edit the following event data in the event.json file with your own data:

{
  "from": "username@gmail.com",
  "to": "receiver@address.com",
  "subject": "Hello",
  "template": "welcome",
  "context": {
    "first_name": "Sam",
    "last_name": "Smith"
  }
}

Then invoke the send function by running serverless invoke -f send -p event.json

This will use the welcome template coupled with the context/data (first_name & last_name). You should receive an email that says:

Welcome Sam Smith

You can edit the template text by editing these two files:

serverless-mailer/lib/templates/html.handlebars
serverless-mailer/lib/templates/text.handlebars

Supported Services

serverless-mailer supports the following 30 service, pre-configured and ready to use. You just provide the service, username & password in env vars as shown earlier:

Template Engines

serverless-mailer comes with a welcome template for demonstration. You can add/remove templates from the following directory:

serverless-mailer/lib/templates/

serverless-mailer uses handlebars as the default template engine. You can use any other template engine by adding it to the module's package.json file and update dependencies with npm install.

Here's the full list of supported templates:

after choosing your template engine, make sure the file extensions of the template files match the template you chose:

html.{{ext}}
text.{{ext}}
style.{{ext}}

Mail Options (Event Properties):

Here's the full list of options you can pass in your event: