All Projects → adnanrahic → lambda-mailer

adnanrahic / lambda-mailer

Licence: MIT license
Simple module for receiving an email from a contact form on your website.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to lambda-mailer

BackportCpp
Library of backported modern C++ types to work with C++11
Stars: ✭ 53 (-36.14%)
Mutual labels:  no-dependencies
spgateway
智付通API串接
Stars: ✭ 20 (-75.9%)
Mutual labels:  node-module
lockbot
🔒 Coordinate use of your team's shared resources, in Slack 🤝
Stars: ✭ 47 (-43.37%)
Mutual labels:  serverless-framework
aws-secure-websockets
Secure web socket implementation using AWS products and serverless framework
Stars: ✭ 49 (-40.96%)
Mutual labels:  serverless-framework
growl-alert
A simple growl like notification system.
Stars: ✭ 14 (-83.13%)
Mutual labels:  no-dependencies
form-saver
A simple script that lets users save and reuse form data.
Stars: ✭ 67 (-19.28%)
Mutual labels:  no-dependencies
amazon-ivs-ugc-web-demo
This repository shows how you can build a compelling user-generated content (UGC) live streaming webapp with Amazon IVS.
Stars: ✭ 14 (-83.13%)
Mutual labels:  serverless-framework
ses-email-client
Simple, serverless client for AWS SES. With this, you can send/read emails received by SES into S3 without purchasing AWS Workmail. If you only use SES for email marketing, you can also see and preview your SES templates in the browser
Stars: ✭ 21 (-74.7%)
Mutual labels:  aws-ses
binrpc
HomeMatic xmlrpc_bin:// protocol server and client
Stars: ✭ 15 (-81.93%)
Mutual labels:  node-module
RussianNounsJS
Склонение существительных по падежам. Обычно требуются только форма в именительном падеже, одушевлённость и род.
Stars: ✭ 29 (-65.06%)
Mutual labels:  no-dependencies
serverlesscloud.cn
Serverless 中文网
Stars: ✭ 15 (-81.93%)
Mutual labels:  serverless-framework
serverless-multicloud-example
An example Node Express app that can be deployed in any major cloud by the Serverless framework
Stars: ✭ 20 (-75.9%)
Mutual labels:  serverless-framework
lambdog-server
Write Netlify functions without pulling your hair out.
Stars: ✭ 15 (-81.93%)
Mutual labels:  serverless-framework
noiiice
a serverless blog built on NuxtJS, AWS, serverless framework, and irrational exuberance.
Stars: ✭ 42 (-49.4%)
Mutual labels:  serverless-framework
aws-serverless-prototype
Serverless Frameworkを使ったAWS Lambdaプロジェクトの試作品
Stars: ✭ 16 (-80.72%)
Mutual labels:  serverless-framework
teaching-nodejs-expressjs-framework-spring-2019-2020
Complete Node-Express Application
Stars: ✭ 16 (-80.72%)
Mutual labels:  node-module
serverless-aws-rust
⚡🏗️ template for new aws lambda serverless rust apps
Stars: ✭ 89 (+7.23%)
Mutual labels:  serverless-framework
serverless-plugin-offline-kinesis-events
⚡ Serverless plugin that works with serverless-offline to allow offline testing of Serverless functions that are triggered by Kinesis events.
Stars: ✭ 15 (-81.93%)
Mutual labels:  serverless-framework
biguint-format
Node.js module to format big uint numbers from a byte array or a Buffer
Stars: ✭ 16 (-80.72%)
Mutual labels:  node-module
terminus-dashboard
Management Dashboard for Terminus DB
Stars: ✭ 16 (-80.72%)
Mutual labels:  node-module

dependencies contributors License: MIT license

cover

Lambda Mailer

Simple module for receiving an email from a contact form on your website.

Note!

Module needs Node.js version 8 or above.

Usage

Configuration is rather simple.

1. Enable your email address in the AWS console -> Simple Email Service

2. Install the module

$ npm i lambda-mailer

3. require() it in your handler.js

// define the options for your email and domain
const options = {
  myEmail: process.env.EMAIL, // myEmail is the email address you enabled in AWS SES in the AWS Console
  myDomain: process.env.DOMAIN // add the domain of your website or '*' if you want to accept requests from any domain
}

// initialize the function
const { sendJSON, sendFormEncoded } = require('lambda-mailer')(options)

// Content-Type: application/json
// The event.body needs to be a JSON object with 3 properties
// - email
// - name
// - content
module.exports.sendJSON = sendJSON

// Content-Type: application/x-www-form-urlencoded
// The event.body needs to a URI encoded string with 3 parameters
// - email
// - name
// - content
module.exports.sendFormEncoded = sendFormEncoded

4. Hook it up to API Gateway in the serverless.yml

service: lambda-mailer

custom:
  secrets: ${file(secrets.json)}

provider:
  name: aws
  runtime: nodejs8.10
  stage: ${self:custom.secrets.NODE_ENV}
  region: us-east-1
  profile: ${self:custom.secrets.PROFILE}
  environment: 
    NODE_ENV: ${self:custom.secrets.NODE_ENV}
    EMAIL: ${self:custom.secrets.EMAIL}
    DOMAIN: ${self:custom.secrets.DOMAIN}
  iamRoleStatements:
    - Effect: "Allow"
      Action:
        - "ses:SendEmail"
      Resource: "*"

functions:
  sendJSON:
    handler: handler.sendJSON
    events:
      - http:
          path: email/send/json
          method: post
          cors: true
  sendFormEncoded:
    handler: handler.sendFormEncoded
    events:
      - http:
          path: email/send/formencoded
          method: post
          cors: true

5. Send an HTTP request to the API Gateway endpoint

Send a POST request of the type JSON with the body as stated below. The sample below is with CURL.

  • request method: POST
  • request body type: application/json
  • request body: { email: String, name: String, content: String }
curl --header "Content-Type: application/json" \
  --request POST \
  --data '{"email":"[email protected]","name":"John Doe","content":"I need some help!"}' \
  https://{id}.execute-api.{region}.amazonaws.com/{stage}/email/send/json

6. Send a regular form POST request to the API Gateway endpoint

Send a POST request using an HTML form. Sample below shows a simple HTML form.

<form action="https://{id}.execute-api.{region}.amazonaws.com/{stage}/dev/email/send/formencoded" method="POST">
  <input type="text" name="name" required>
  <input type="email" name="email" required>
  <textarea name="content" required></textarea>
</form>

By default the request will redirect back to the initial page the request was sent from. You can edit the redirectUrl by adding it as a query string parameter. Example below.

<form action="https://{id}.execute-api.{region}.amazonaws.com/{stage}/dev/email/send/formencoded?redirectUrl=https://someotherdomain.com" method="POST">
  <input type="text" name="name" required>
  <input type="email" name="email" required>
  <textarea name="content" required></textarea>
</form>

Enjoy using the module. Feel free to open issues or feature requests. 😄

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].