npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

lambda-mailer

v0.2.0

Published

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

Downloads

5

Readme

dependencies contributors License: MIT license

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. :smile: