Browse Source

Add SES email forwarding service

Josh Habdas 2 years ago
parent
commit
99117d58d1
No account linked to committer's email address

+ 1
- 2
.gitignore View File

@@ -1,9 +1,8 @@
1
-*.sublime-project
2
-*.sublime-workspace
3 1
 .DS_Store
4 2
 .jekyll-metadata
5 3
 .sass-cache
6 4
 .asset-cache
5
+.serverless
7 6
 _asset_bundler_cache
8 7
 _site
9 8
 codekit-config.json

+ 20
- 0
services/ses-forwarder/README.md View File

@@ -0,0 +1,20 @@
1
+# Overview
2
+
3
+Forwards emails sent to `whatever@habd.as` to `jhabdas@gmail.com` using SES.
4
+
5
+# Usage
6
+
7
+- Set `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY` for Serverless IAM user
8
+  **Note:** Can be set as env vars or configured under home directory.
9
+- Do the wild thing
10
+
11
+# Todo
12
+
13
+- [] Integrate with CI for automated Lambda updates
14
+
15
+# Resources
16
+
17
+- https://spinscale.de/posts/2016-06-16-using-claudia-js-and-recaptcha-to-send-emails-with-aws-lambda.html
18
+- https://jeremyfelt.com/2016/05/22/send-receive-email-domain-postmark-amazons-ses-s3-lambda-services/
19
+- https://github.com/arithmetric/aws-lambda-ses-forwarder/blob/master/example/index.js
20
+- https://github.com/serverless/serverless/tree/master/docs

+ 97
- 0
services/ses-forwarder/event.json View File

@@ -0,0 +1,97 @@
1
+{
2
+  "Records": [
3
+    {
4
+      "eventVersion": "1.0",
5
+      "ses": {
6
+        "mail": {
7
+          "commonHeaders": {
8
+            "from": [
9
+              "Bridget Fonda <bfonda@pointofno.return>"
10
+            ],
11
+            "to": [
12
+              "postmaster@habd.as"
13
+            ],
14
+            "returnPath": "bfonda@pointofno.return",
15
+            "messageId": "<0123456789habd.as>",
16
+            "date": "Wed, 7 Oct 2015 12:34:56 -0700",
17
+            "subject": "I never did mind the little things"
18
+          },
19
+          "source": "bfonda@pointofno.return",
20
+          "timestamp": "1970-01-01T00:00:00.000Z",
21
+          "destination": [
22
+            "postmaster@habd.as"
23
+          ],
24
+          "headers": [
25
+            {
26
+              "name": "Return-Path",
27
+              "value": "<bfonda@pointofno.return>"
28
+            },
29
+            {
30
+              "name": "Received",
31
+              "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)"
32
+            },
33
+            {
34
+              "name": "DKIM-Signature",
35
+              "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=="
36
+            },
37
+            {
38
+              "name": "MIME-Version",
39
+              "value": "1.0"
40
+            },
41
+            {
42
+              "name": "From",
43
+              "value": "Bridget Fonda <bfonda@pointofno.return>"
44
+            },
45
+            {
46
+              "name": "Date",
47
+              "value": "Wed, 7 Oct 2015 12:34:56 -0700"
48
+            },
49
+            {
50
+              "name": "Message-ID",
51
+              "value": "<0123456789habd.as>"
52
+            },
53
+            {
54
+              "name": "Subject",
55
+              "value": "I never did mind the little things"
56
+            },
57
+            {
58
+              "name": "To",
59
+              "value": "postmaster@habd.as"
60
+            },
61
+            {
62
+              "name": "Content-Type",
63
+              "value": "text/plain; charset=UTF-8"
64
+            }
65
+          ],
66
+          "headersTruncated": false,
67
+          "messageId": "o3vrnil0e2ic28trm7dfhrc2v0clambda4nbp0g1"
68
+        },
69
+        "receipt": {
70
+          "recipients": [
71
+            "postmaster@habd.as"
72
+          ],
73
+          "timestamp": "1970-01-01T00:00:00.000Z",
74
+          "spamVerdict": {
75
+            "status": "PASS"
76
+          },
77
+          "dkimVerdict": {
78
+            "status": "PASS"
79
+          },
80
+          "processingTimeMillis": 574,
81
+          "action": {
82
+            "type": "Lambda",
83
+            "invocationType": "Event",
84
+            "functionArn": "arn:aws:lambda:us-west-2:012345678912:function:Example"
85
+          },
86
+          "spfVerdict": {
87
+            "status": "PASS"
88
+          },
89
+          "virusVerdict": {
90
+            "status": "PASS"
91
+          }
92
+        }
93
+      },
94
+      "eventSource": "aws:ses"
95
+    }
96
+  ]
97
+}

+ 30
- 0
services/ses-forwarder/handler.js View File

@@ -0,0 +1,30 @@
1
+'use strict';
2
+
3
+var sesForwarder = require('aws-lambda-ses-forwarder')
4
+
5
+module.exports.sesForwarder = function (evt, ctx) {
6
+  // Configure the S3 bucket and key prefix for stored raw emails, and the
7
+  // mapping of email addresses to forward from and to.
8
+  //
9
+  // Expected keys/values:
10
+  // - fromEmail: Forwarded emails will come from this verified address
11
+  // - emailBucket: S3 bucket name where SES stores emails.
12
+  // - emailKeyPrefix: S3 key name prefix where SES stores email. Include the
13
+  //   trailing slash.
14
+  // - forwardMapping: Object where the key is the email address from which to
15
+  //   forward and the value is an array of email addresses to which to send the
16
+  //   message.
17
+  var overrides = {
18
+    config: {
19
+      fromEmail: "noreply@habd.as",
20
+      emailBucket: "habd.as-ses-email",
21
+      emailKeyPrefix: "",
22
+      forwardMapping: {
23
+        "@habd.as": [
24
+          "jhabdas@gmail.com"
25
+        ]
26
+      }
27
+    }
28
+  };
29
+  sesForwarder.handler(evt, ctx, overrides);
30
+}

+ 17
- 0
services/ses-forwarder/package.json View File

@@ -0,0 +1,17 @@
1
+{
2
+  "name": "ses-forwarder",
3
+  "version": "1.0.0",
4
+  "private": true,
5
+  "description": "Forward email with Lambda to SES-verified email address.",
6
+  "scripts": {
7
+    "lambda-tail": "smoketail -f /aws/lambda/ses-forwarder-dev-sesForwarder",
8
+    "lambda-deploy": "serverless deploy"
9
+  },
10
+  "dependencies": {
11
+    "aws-lambda-ses-forwarder": "^3.0.0"
12
+  },
13
+  "devDependencies": {
14
+    "serverless": "^1.0.0-beta.2",
15
+    "smoketail": "^0.1.0"
16
+  }
17
+}

+ 15
- 0
services/ses-forwarder/serverless.env.yml View File

@@ -0,0 +1,15 @@
1
+# This is the Serverless Environment File
2
+#
3
+# It contains listing of your stages and their regions
4
+# It also manages serverless variables at 3 levels:
5
+#    - common variables: variables that apply to all stages/regions
6
+#    - stage variables: variables that apply to a specific stage
7
+#    - region variables: variables that apply to a specific region
8
+
9
+vars:
10
+stages:
11
+  dev:
12
+    vars:
13
+    regions:
14
+      us-west-2:
15
+        vars:

+ 53
- 0
services/ses-forwarder/serverless.yml View File

@@ -0,0 +1,53 @@
1
+# Welcome to Serverless!
2
+#
3
+# This file is the main config file for your service.
4
+# It's very minimal at this point and uses default values.
5
+# You can always add more config options for more control.
6
+# We've included some commented out config examples here.
7
+# Just uncomment any of them to get that config option.
8
+#
9
+# For full config options, check the docs:
10
+#    v1.docs.serverless.com
11
+#
12
+# Happy Coding!
13
+
14
+service: ses-forwarder
15
+
16
+provider:
17
+  name: aws
18
+  runtime: nodejs4.3
19
+
20
+# you can overwrite defaults here
21
+defaults:
22
+   region: us-west-2
23
+#  stage: dev
24
+
25
+# you can add packaging information here
26
+#package:
27
+#  include:
28
+#    - include-me.js
29
+#  exclude:
30
+#    - exclude-me.js
31
+#  artifact: my-service-code.zip
32
+
33
+functions:
34
+  sesForwarder:
35
+    handler: handler.sesForwarder
36
+    memorySize: 128 # optional, default is 1024
37
+    timeout: 10 # optional, default is 6
38
+    # events:
39
+    #   - s3: habd.as-ses-email # ${bucket}
40
+    #   - schedule: rate(10 minutes)
41
+    #   - sns: habd_as-ses
42
+
43
+# you can add CloudFormation resource templates here
44
+#resources:
45
+#  Resources:
46
+#    NewResource:
47
+#      Type: AWS::S3::Bucket
48
+#      Properties:
49
+#        BucketName: my-new-bucket
50
+#  Outputs:
51
+#     NewOutput:
52
+#       Description: "Description for the output"
53
+#       Value: "Some output value"

Loading…
Cancel
Save