Giter Site home page Giter Site logo

lambda-mailer's Introduction

โœ‰๏ธ 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

  • 30+ pre-configured services (Gmail, Hotmail, SendGrid...etc)
  • HTML content as well as plain text alternative
  • 30+ supported HTML template engines (handlebars, jade, haml...etc)
  • Easy HTML styling with Juice
  • Embedded images in HTML
  • Email Attachments
  • Unicode to use any characters

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 protected]
EMAIL_SERVICE_PASS=password

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

EMAIL_SERVICE=gmail
[email protected]
EMAIL_SERVICE_PASS=password

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

{
  "from": "[email protected]",
  "to": "[email protected]",
  "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:

  • '1und1'
  • 'AOL'
  • 'DebugMail.io'
  • 'DynectEmail'
  • 'FastMail'
  • 'GandiMail'
  • 'Gmail'
  • 'Godaddy'
  • 'GodaddyAsia'
  • 'GodaddyEurope'
  • 'hot.ee'
  • 'Hotmail'
  • 'iCloud'
  • 'mail.ee'
  • 'Mail.ru'
  • 'Mailgun'
  • 'Mailjet'
  • 'Mandrill'
  • 'Naver'
  • 'Postmark'
  • 'QQ'
  • 'QQex'
  • 'SendCloud'
  • 'SendGrid'
  • 'SES'
  • 'Sparkpost'
  • 'Yahoo'
  • 'Yandex'
  • 'Zoho'

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:

  • from - The e-mail address of the sender. All e-mail addresses can be plain '[email protected]' or formatted 'Sender Name <[email protected]>', see here for details
  • sender - An e-mail address that will appear on the Sender: field
  • to - Comma separated list or an array of recipients e-mail addresses that will appear on the To: field
  • cc - Comma separated list or an array of recipients e-mail addresses that will appear on the Cc: field
  • bcc - Comma separated list or an array of recipients e-mail addresses that will appear on the Bcc: field
  • replyTo - An e-mail address that will appear on the Reply-To: field
  • inReplyTo - The message-id this message is replying
  • references - Message-id list (an array or space separated string)
  • subject - The subject of the e-mail
  • template - The template to use for this email. Make sure it matches one of the folder names inside the templates folder
  • context - The context/data the template needs. eg. {"first_name": "..."}
  • watchHtml - Apple Watch specific HTML version of the message (experimental)
  • headers - An object or array of additional header fields (e.g. {"X-Key-Name": "key value"} or [{key: "X-Key-Name", value: "val1"}, {key: "X-Key-Name", value: "val2"}])
  • attachments - An array of attachment objects
  • alternatives - An array of alternative text contents (in addition to text and html parts)
  • envelope - optional SMTP envelope, if auto generated envelope is not suitable
  • messageId - optional Message-Id value, random value will be generated if not set
  • date - optional Date value, current UTC string will be used if not set
  • encoding - optional transfer encoding for the textual parts

lambda-mailer's People

Contributors

eahefnawy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

lambda-mailer's Issues

Can we use SES

Instead of using Nodemailer module and authenticating with SMPT credentials can we use SES and allow the IAM policy to allow SendEmail?

Path must be a string (received undefined)

Hello,

I'm invoking the function from another lambda. The function is triggered, but the email doesn't succeed:

2017-04-25T00:06:57.273Z	13c6055f-294b-11e7-a972-e75138f1d5c4	TypeError: Path must be a string. Received undefined
at assertPath (path.js:7:11)
at Object.join (path.js:1211:7)
at Object.module.exports.run (/var/task/mailer.js:21:26)
at exports.handler (/var/task/index.js:6:10)

The invocation is done as this:

import * as aws from 'aws-sdk'
var lambda = new aws.Lambda();

          var params = {
            FunctionName: 'aws_lambda_mailer-dev',
            InvocationType: 'RequestResponse',
            LogType: 'Tail',
            Payload: '{ test: test }'
          };

          lambda.invoke(params, function(err, data) {
            if (err) {
              context.fail(err);
              console.log('Error sending message: ' + err);
            } else {
              context.succeed('Lambda message: '+ data.Payload);
              console.log('Lambda message: ' + data.Payload);
            }
          })

And in the logs I only get information about an error:

2017-04-25T07:16:05.932Z	04548153-2987-11e7-ac80-8186ddeda411	Lambda message:
{
    "errorMessage": "RequestId: 066b7a6c-2987-11e7-8954-c35459870107 Process exited before completing request"
}

Any idea about why the path might be undefined? When the function is invoked manually (via the test console) the path is found correctly.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.