Home

Awesome

:envelope: lambda-mailer

AWS Lambda for sending emails. Ready for deployment in 60 seocnds.

This lambda gives your browser (or any client) a backend for sending emails.

Features

Quick Usage

// install node-lambda
npm install -g node-lambda

// clone the lambda and get inside!
git clone https://github.com/eahefnawy/lambda-mailer.git
cd  lambda-mailer

// install dependencies
npm install

// create deployment files (to hold your env vars)
touch .env deploy.env event.json

.env file is used by your local machine to test and deploy the lambda, deploy.env is used by your lambda function after deployment. So there might be some duplicate env vars.

open .env and fill it with your AWS credentials: (make sure you have proper IAM permissions)

AWS_ENVIRONMENT=dev
AWS_ACCESS_KEY_ID=your_key
AWS_SECRET_ACCESS_KEY=your_secret
AWS_SESSION_TOKEN=your_sesson token (optional)
AWS_ROLE_ARN=your_amazon_role
AWS_REGION=us-east-1
AWS_FUNCTION_NAME=your_lambda_name
AWS_HANDLER=index.handler
AWS_MODE=event
AWS_MEMORY_SIZE=128
AWS_TIMEOUT=60
AWS_DESCRIPTION=your_lambda_description
AWS_RUNTIME=nodejs
CONFIG_FILE=deploy.env

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

open deploy.env and fill it with your gmail credentials:

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

open event.json and fill it with the following sample event: (just change the to and from Properties)

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

now everything is set! Let's test locally!

node-lambda run

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:

lambda-mailer/templates/welcome/html.handlebars
lambda-mailer/templates/welcome/text.handlebars

now that it works locally, let's deploy to AWS:

node-lambda deploy

That's it! Now you can call the lambda from any AWS SDK, like your browser JS SDK.

Supported Services

lambda-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

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

lambda-mailer/templates/

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

Here's the full list of supported templates:

after chosing your template engine, make sure the file extentions 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: