Permalink
Browse files

Add SES email forwarding service

1 parent f6b0ad2 commit 99117d58d156e05a920611b47efb59f080ca2b26 @jhabdas committed Aug 27, 2016
View
@@ -1,9 +1,8 @@
-*.sublime-project
-*.sublime-workspace
.DS_Store
.jekyll-metadata
.sass-cache
.asset-cache
+.serverless
_asset_bundler_cache
_site
codekit-config.json
@@ -0,0 +1,20 @@
+# Overview
+
+Forwards emails sent to `whatever@habd.as` to `jhabdas@gmail.com` using SES.
+
+# Usage
+
+- Set `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY` for Serverless IAM user
+ **Note:** Can be set as env vars or configured under home directory.
+- Do the wild thing
+
+# Todo
+
+- [] Integrate with CI for automated Lambda updates
+
+# Resources
+
+- https://spinscale.de/posts/2016-06-16-using-claudia-js-and-recaptcha-to-send-emails-with-aws-lambda.html
+- https://jeremyfelt.com/2016/05/22/send-receive-email-domain-postmark-amazons-ses-s3-lambda-services/
+- https://github.com/arithmetric/aws-lambda-ses-forwarder/blob/master/example/index.js
+- https://github.com/serverless/serverless/tree/master/docs
@@ -0,0 +1,97 @@
+{
+ "Records": [
+ {
+ "eventVersion": "1.0",
+ "ses": {
+ "mail": {
+ "commonHeaders": {
+ "from": [
+ "Bridget Fonda <bfonda@pointofno.return>"
+ ],
+ "to": [
+ "postmaster@habd.as"
+ ],
+ "returnPath": "bfonda@pointofno.return",
+ "messageId": "<0123456789habd.as>",
+ "date": "Wed, 7 Oct 2015 12:34:56 -0700",
+ "subject": "I never did mind the little things"
+ },
+ "source": "bfonda@pointofno.return",
+ "timestamp": "1970-01-01T00:00:00.000Z",
+ "destination": [
+ "postmaster@habd.as"
+ ],
+ "headers": [
+ {
+ "name": "Return-Path",
+ "value": "<bfonda@pointofno.return>"
+ },
+ {
+ "name": "Received",
+ "value": "from mailer.example.com (mailer.example.com [203.0.113.1]) by inbound-smtp.us-west-2.amazonaws.com with SMTP id o3vrnil0e2ic28trm7dfhrc2v0cnbeccl4nbp0g1 for johndoe@example.com; Wed, 07 Oct 2015 12:34:56 +0000 (UTC)"
+ },
+ {
+ "name": "DKIM-Signature",
+ "value": "v=1; a=rsa-sha256; c=relaxed/relaxed; d=example.com; s=example; h=mime-version:from:date:message-id:subject:to:content-type; bh=jX3F0bCAI7sIbkHyy3mLYO28ieDQz2R0P8HwQkklFj4=; b=sQwJ+LMe9RjkesGu+vqU56asvMhrLRRYrWCbVt6WJulueecwfEwRf9JVWgkBTKiL6m2hr70xDbPWDhtLdLO+jB3hzjVnXwK3pYIOHw3vxG6NtJ6o61XSUwjEsp9tdyxQjZf2HNYee873832l3K1EeSXKzxYk9Pwqcpi3dMC74ct9GukjIevf1H46hm1L2d9VYTL0LGZGHOAyMnHmEGB8ZExWbI+k6khpurTQQ4sp4PZPRlgHtnj3Zzv7nmpTo7dtPG5z5S9J+L+Ba7dixT0jn3HuhaJ9b+VThboo4YfsX9PMNhWWxGjVksSFOcGluPO7QutCPyoY4gbxtwkN9W69HA=="
+ },
+ {
+ "name": "MIME-Version",
+ "value": "1.0"
+ },
+ {
+ "name": "From",
+ "value": "Bridget Fonda <bfonda@pointofno.return>"
+ },
+ {
+ "name": "Date",
+ "value": "Wed, 7 Oct 2015 12:34:56 -0700"
+ },
+ {
+ "name": "Message-ID",
+ "value": "<0123456789habd.as>"
+ },
+ {
+ "name": "Subject",
+ "value": "I never did mind the little things"
+ },
+ {
+ "name": "To",
+ "value": "postmaster@habd.as"
+ },
+ {
+ "name": "Content-Type",
+ "value": "text/plain; charset=UTF-8"
+ }
+ ],
+ "headersTruncated": false,
+ "messageId": "o3vrnil0e2ic28trm7dfhrc2v0clambda4nbp0g1"
+ },
+ "receipt": {
+ "recipients": [
+ "postmaster@habd.as"
+ ],
+ "timestamp": "1970-01-01T00:00:00.000Z",
+ "spamVerdict": {
+ "status": "PASS"
+ },
+ "dkimVerdict": {
+ "status": "PASS"
+ },
+ "processingTimeMillis": 574,
+ "action": {
+ "type": "Lambda",
+ "invocationType": "Event",
+ "functionArn": "arn:aws:lambda:us-west-2:012345678912:function:Example"
+ },
+ "spfVerdict": {
+ "status": "PASS"
+ },
+ "virusVerdict": {
+ "status": "PASS"
+ }
+ }
+ },
+ "eventSource": "aws:ses"
+ }
+ ]
+}
@@ -0,0 +1,30 @@
+'use strict';
+
+var sesForwarder = require('aws-lambda-ses-forwarder')
+
+module.exports.sesForwarder = function (evt, ctx) {
+ // Configure the S3 bucket and key prefix for stored raw emails, and the
+ // mapping of email addresses to forward from and to.
+ //
+ // Expected keys/values:
+ // - fromEmail: Forwarded emails will come from this verified address
+ // - emailBucket: S3 bucket name where SES stores emails.
+ // - emailKeyPrefix: S3 key name prefix where SES stores email. Include the
+ // trailing slash.
+ // - forwardMapping: Object where the key is the email address from which to
+ // forward and the value is an array of email addresses to which to send the
+ // message.
+ var overrides = {
+ config: {
+ fromEmail: "noreply@habd.as",
+ emailBucket: "habd.as-ses-email",
+ emailKeyPrefix: "",
+ forwardMapping: {
+ "@habd.as": [
+ "jhabdas@gmail.com"
+ ]
+ }
+ }
+ };
+ sesForwarder.handler(evt, ctx, overrides);
+}
@@ -0,0 +1,17 @@
+{
+ "name": "ses-forwarder",
+ "version": "1.0.0",
+ "private": true,
+ "description": "Forward email with Lambda to SES-verified email address.",
+ "scripts": {
+ "lambda-tail": "smoketail -f /aws/lambda/ses-forwarder-dev-sesForwarder",
+ "lambda-deploy": "serverless deploy"
+ },
+ "dependencies": {
+ "aws-lambda-ses-forwarder": "^3.0.0"
+ },
+ "devDependencies": {
+ "serverless": "^1.0.0-beta.2",
+ "smoketail": "^0.1.0"
+ }
+}
@@ -0,0 +1,15 @@
+# This is the Serverless Environment File
+#
+# It contains listing of your stages and their regions
+# It also manages serverless variables at 3 levels:
+# - common variables: variables that apply to all stages/regions
+# - stage variables: variables that apply to a specific stage
+# - region variables: variables that apply to a specific region
+
+vars:
+stages:
+ dev:
+ vars:
+ regions:
+ us-west-2:
+ vars:
@@ -0,0 +1,53 @@
+# Welcome to Serverless!
+#
+# This file is the main config file for your service.
+# It's very minimal at this point and uses default values.
+# You can always add more config options for more control.
+# We've included some commented out config examples here.
+# Just uncomment any of them to get that config option.
+#
+# For full config options, check the docs:
+# v1.docs.serverless.com
+#
+# Happy Coding!
+
+service: ses-forwarder
+
+provider:
+ name: aws
+ runtime: nodejs4.3
+
+# you can overwrite defaults here
+defaults:
+ region: us-west-2
+# stage: dev
+
+# you can add packaging information here
+#package:
+# include:
+# - include-me.js
+# exclude:
+# - exclude-me.js
+# artifact: my-service-code.zip
+
+functions:
+ sesForwarder:
+ handler: handler.sesForwarder
+ memorySize: 128 # optional, default is 1024
+ timeout: 10 # optional, default is 6
+ # events:
+ # - s3: habd.as-ses-email # ${bucket}
+ # - schedule: rate(10 minutes)
+ # - sns: habd_as-ses
+
+# you can add CloudFormation resource templates here
+#resources:
+# Resources:
+# NewResource:
+# Type: AWS::S3::Bucket
+# Properties:
+# BucketName: my-new-bucket
+# Outputs:
+# NewOutput:
+# Description: "Description for the output"
+# Value: "Some output value"

0 comments on commit 99117d5

Please sign in to comment.