From cd874780659d81db0fc99bd16be85beae0d6ec9c Mon Sep 17 00:00:00 2001 From: Axel Uhl Date: Tue, 14 Apr 2020 23:18:12 +0000 Subject: [PATCH 1/9] Updated home (markdown) --- home.md | 1 + 1 file changed, 1 insertion(+) diff --git a/home.md b/home.md index f49b2da2c1e..65c8056a42f 100644 --- a/home.md +++ b/home.md @@ -35,6 +35,7 @@ SAP is at the center of today’s technology revolution, developing innovations * [[Creating an EC2 image from scratch|wiki/info/landscape/creating-ec2-image-from-scratch]] * [[Creating a webserver EC2 image from scratch|wiki/info/landscape/creating-ec2-image-for-webserver-from-scratch]] * [[EC2 mail relaying vs. Amazon Simple E-Mail Service (SES)|wiki/info/landscape/mail-relaying]] + * [[Establishing support@sapsailing.com with AWS SES, SNS, and Lambda|wiki/info/landscape/support-email]] * [[Creating an EC2 image for a MongoDB Replica Set from scratch|wiki/info/landscape/creating-ec2-mongodb-image-from-scratch]] * [[Setting up dedicated S3 buckets|wiki/info/landscape/s3-bucket-setup]] * [[Building and Deploying|wiki/info/landscape/building-and-deploying]] From 25b51d5ac85d813fb4dbec1eb42015977859f552 Mon Sep 17 00:00:00 2001 From: Axel Uhl Date: Wed, 15 Apr 2020 01:38:58 +0200 Subject: [PATCH 2/9] AWS Lambda for e-mail forwarding --- configuration/mail_forward.js | 38 ++++++++++++++++++++++++++ configuration/mail_forward_policy.json | 22 +++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 configuration/mail_forward.js create mode 100644 configuration/mail_forward_policy.json diff --git a/configuration/mail_forward.js b/configuration/mail_forward.js new file mode 100644 index 00000000000..6bc037db681 --- /dev/null +++ b/configuration/mail_forward.js @@ -0,0 +1,38 @@ +// Taken from https://github.com/sirceljm/AWS-SES-simple-mail-forward/blob/master/mail_forward.js +// Install as an AWS Lambda according to https://github.com/sirceljm/AWS-SES-simple-mail-forward +// and configure the to_address environment variable as a JSON array of strings representing +// the recipients' e-mail addresses. Subscribe the lambda to your SNS topic that receives the +// notification messages about your inbound e-mail. Use mail_forward_policy.json for the IAM role's +// security policy. +var AWS = require("aws-sdk"); +var ses = new AWS.SES(); + +exports.handler = (event, context, callback) => { + let data = JSON.parse(event.Records[0].Sns.Message); + let source = data.content; + + source = source.replace(/^DKIM-Signature/im, "X-Original-DKIM-Signature"); + // source = source.replace(/^From/im, "X-Original-From"); + // source = source.replace(/^Source/im, "X-Original-Source"); + // source = source.replace(/^Sender/im, "X-Original-Sender"); + // source = source.replace(/^Return-Path/im, "X-Original-Return-Path"); + source = source.replace(/^Domainkey-Signature/im, "X-Original-Domainkey-Signature"); + // source = `From: AWS SES Mail Forwarding <${data.mail.destination}>\n` + source; + + if (!process.env.to_address) { + console.log("You need to supply to_address enviromnent variable"); + } else if (data.mail.destination == process.env.to_address) { + console.log("MAIL SEND ABORTED! - Forwarded mail address and to_address are the same - THIS CAN CAUSE AN INFINITE LOOP!"); + } else { + ses.sendRawEmail({ + RawMessage: { + Data: source, + }, + Destinations: JSON.parse(process.env.to_address), + }, function (err, data) { + if (err) { + console.error(err, err.stack); + } + }); + } +}; diff --git a/configuration/mail_forward_policy.json b/configuration/mail_forward_policy.json new file mode 100644 index 00000000000..e586059e9e8 --- /dev/null +++ b/configuration/mail_forward_policy.json @@ -0,0 +1,22 @@ +{ + "Version": "2012-10-17", + "Statement": [ + { + "Effect": "Allow", + "Action": [ + "logs:CreateLogGroup", + "logs:CreateLogStream", + "logs:PutLogEvents" + ], + "Resource": "arn:aws:logs:*:*:*" + }, + { + "Effect": "Allow", + "Action": [ + "ses:SendEmail", + "ses:SendRawEmail" + ], + "Resource": "*" + } + ] +} From 8772c1b3c229174e4c59ba9334f6608d90d0933d Mon Sep 17 00:00:00 2001 From: Axel Uhl Date: Tue, 14 Apr 2020 23:43:02 +0000 Subject: [PATCH 3/9] Created support email (markdown) --- ...ailing-dot-com-with-AWS-SES-slash-SNS-slash-Lambda.md | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 wiki/info/landscape/Set-Up-of-Support-E-Mail-Address-support-at-sapsailing-dot-com-with-AWS-SES-slash-SNS-slash-Lambda.md diff --git a/wiki/info/landscape/Set-Up-of-Support-E-Mail-Address-support-at-sapsailing-dot-com-with-AWS-SES-slash-SNS-slash-Lambda.md b/wiki/info/landscape/Set-Up-of-Support-E-Mail-Address-support-at-sapsailing-dot-com-with-AWS-SES-slash-SNS-slash-Lambda.md new file mode 100644 index 00000000000..7bb25524adb --- /dev/null +++ b/wiki/info/landscape/Set-Up-of-Support-E-Mail-Address-support-at-sapsailing-dot-com-with-AWS-SES-slash-SNS-slash-Lambda.md @@ -0,0 +1,9 @@ +We use AWS SES for all e-mail services, inbound and outbound. See also [Amazon Simple Email Service (SES) Set-Up](wiki/info/landscape/mail-relaying) for details on the general SES set-up. We have established ``support@sapsailing.com`` now as another inbound e-mail address that forwards to an SNS topic named ``Support-Mail``. + +The messages forwarded from SES to SNS are JSON-formatted wrappers around the original e-mail message augmented with various meta-data. Forwarding these messages with a straight SNS subscription of type EMAIL results in human-unreadable e-mails in JSON format with all the metadata included. + +Instead, we subscribe a Lambda function on the ``Support-Mail`` SNS topic that parses the original message from the JSON document and re-sends it through SES to a list of recipients that can be configured in the ``to_address`` environment variable used by the Lambda. The ``to_address`` environment variable needs to be a valid JSON array that contains the recipients' e-mail addresses as string objects. + +The role that is created to execute the Lambda needs to have a policy set that can access SES and write logs. See also https://github.com/sirceljm/AWS-SES-simple-mail-forward/blob/master/mail_forward_policy.json. + +The relevant files have been committed to our git as ``configuration/mail_forward.js`` for the Lambda's code, and as ``configuration/mail_forward_policy.json`` for the security policy for the IAM role used for the Lambda. \ No newline at end of file From ca4375df5178164a2e34c43588fc2519f69b8342 Mon Sep 17 00:00:00 2001 From: Axel Uhl Date: Tue, 14 Apr 2020 23:45:24 +0000 Subject: [PATCH 4/9] Updated home (markdown) --- home.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/home.md b/home.md index 65c8056a42f..b552761d4b9 100644 --- a/home.md +++ b/home.md @@ -35,7 +35,7 @@ SAP is at the center of today’s technology revolution, developing innovations * [[Creating an EC2 image from scratch|wiki/info/landscape/creating-ec2-image-from-scratch]] * [[Creating a webserver EC2 image from scratch|wiki/info/landscape/creating-ec2-image-for-webserver-from-scratch]] * [[EC2 mail relaying vs. Amazon Simple E-Mail Service (SES)|wiki/info/landscape/mail-relaying]] - * [[Establishing support@sapsailing.com with AWS SES, SNS, and Lambda|wiki/info/landscape/support-email]] + * [[Establishing support@sapsailing.com with AWS SES, SNS, and Lambda|wiki/info/landscape/Set-Up-of-Support-E-Mail-Address-support-at-sapsailing-dot-com-with-AWS-SES-slash-SNS-slash-Lambda]] * [[Creating an EC2 image for a MongoDB Replica Set from scratch|wiki/info/landscape/creating-ec2-mongodb-image-from-scratch]] * [[Setting up dedicated S3 buckets|wiki/info/landscape/s3-bucket-setup]] * [[Building and Deploying|wiki/info/landscape/building-and-deploying]] From 6134c6e54eeb7d32535217cce2bd90ab22298efa Mon Sep 17 00:00:00 2001 From: Axel Uhl Date: Tue, 14 Apr 2020 23:46:57 +0000 Subject: [PATCH 5/9] Renamed Set Up of Support E Mail Address support at sapsailing dot com with AWS SES slash SNS slash Lambda to support-email --- ...om-with-AWS-SES-slash-SNS-slash-Lambda.md => support-email.md} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename wiki/info/landscape/{Set-Up-of-Support-E-Mail-Address-support-at-sapsailing-dot-com-with-AWS-SES-slash-SNS-slash-Lambda.md => support-email.md} (100%) diff --git a/wiki/info/landscape/Set-Up-of-Support-E-Mail-Address-support-at-sapsailing-dot-com-with-AWS-SES-slash-SNS-slash-Lambda.md b/wiki/info/landscape/support-email.md similarity index 100% rename from wiki/info/landscape/Set-Up-of-Support-E-Mail-Address-support-at-sapsailing-dot-com-with-AWS-SES-slash-SNS-slash-Lambda.md rename to wiki/info/landscape/support-email.md From e37fb6948c5b53ae2464db9c9eeb8f7545e981c9 Mon Sep 17 00:00:00 2001 From: Axel Uhl Date: Tue, 14 Apr 2020 23:47:31 +0000 Subject: [PATCH 6/9] Updated home (markdown) --- home.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/home.md b/home.md index b552761d4b9..65c8056a42f 100644 --- a/home.md +++ b/home.md @@ -35,7 +35,7 @@ SAP is at the center of today’s technology revolution, developing innovations * [[Creating an EC2 image from scratch|wiki/info/landscape/creating-ec2-image-from-scratch]] * [[Creating a webserver EC2 image from scratch|wiki/info/landscape/creating-ec2-image-for-webserver-from-scratch]] * [[EC2 mail relaying vs. Amazon Simple E-Mail Service (SES)|wiki/info/landscape/mail-relaying]] - * [[Establishing support@sapsailing.com with AWS SES, SNS, and Lambda|wiki/info/landscape/Set-Up-of-Support-E-Mail-Address-support-at-sapsailing-dot-com-with-AWS-SES-slash-SNS-slash-Lambda]] + * [[Establishing support@sapsailing.com with AWS SES, SNS, and Lambda|wiki/info/landscape/support-email]] * [[Creating an EC2 image for a MongoDB Replica Set from scratch|wiki/info/landscape/creating-ec2-mongodb-image-from-scratch]] * [[Setting up dedicated S3 buckets|wiki/info/landscape/s3-bucket-setup]] * [[Building and Deploying|wiki/info/landscape/building-and-deploying]] From 28df0b5ca229160295845dbc0c14b35bab2aaa18 Mon Sep 17 00:00:00 2001 From: Axel Uhl Date: Tue, 14 Apr 2020 23:48:50 +0000 Subject: [PATCH 7/9] Updated support email (markdown) --- wiki/info/landscape/support-email.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/wiki/info/landscape/support-email.md b/wiki/info/landscape/support-email.md index 7bb25524adb..bb74948307a 100644 --- a/wiki/info/landscape/support-email.md +++ b/wiki/info/landscape/support-email.md @@ -1,3 +1,5 @@ +# Set Up of Support E Mail Address support at sapsailing dot com with AWS SES slash SNS slash Lambda + We use AWS SES for all e-mail services, inbound and outbound. See also [Amazon Simple Email Service (SES) Set-Up](wiki/info/landscape/mail-relaying) for details on the general SES set-up. We have established ``support@sapsailing.com`` now as another inbound e-mail address that forwards to an SNS topic named ``Support-Mail``. The messages forwarded from SES to SNS are JSON-formatted wrappers around the original e-mail message augmented with various meta-data. Forwarding these messages with a straight SNS subscription of type EMAIL results in human-unreadable e-mails in JSON format with all the metadata included. From 79706021232a1e7d55b922f52d9bcf215f7208b3 Mon Sep 17 00:00:00 2001 From: Axel Uhl Date: Tue, 14 Apr 2020 23:49:48 +0000 Subject: [PATCH 8/9] Updated support email (markdown) --- wiki/info/landscape/support-email.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wiki/info/landscape/support-email.md b/wiki/info/landscape/support-email.md index bb74948307a..935b38f2047 100644 --- a/wiki/info/landscape/support-email.md +++ b/wiki/info/landscape/support-email.md @@ -1,4 +1,4 @@ -# Set Up of Support E Mail Address support at sapsailing dot com with AWS SES slash SNS slash Lambda +# Set Up of Support E Mail Address support@sapsailing.com with AWS SES/SNS/Lambda We use AWS SES for all e-mail services, inbound and outbound. See also [Amazon Simple Email Service (SES) Set-Up](wiki/info/landscape/mail-relaying) for details on the general SES set-up. We have established ``support@sapsailing.com`` now as another inbound e-mail address that forwards to an SNS topic named ``Support-Mail``. From 06fe15e1df7e74f8229592eddf089208beb1ac21 Mon Sep 17 00:00:00 2001 From: Axel Uhl Date: Tue, 14 Apr 2020 23:56:44 +0000 Subject: [PATCH 9/9] Updated support email (markdown) --- wiki/info/landscape/support-email.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/wiki/info/landscape/support-email.md b/wiki/info/landscape/support-email.md index 935b38f2047..ffd8995cb44 100644 --- a/wiki/info/landscape/support-email.md +++ b/wiki/info/landscape/support-email.md @@ -8,4 +8,8 @@ Instead, we subscribe a Lambda function on the ``Support-Mail`` SNS topic that p The role that is created to execute the Lambda needs to have a policy set that can access SES and write logs. See also https://github.com/sirceljm/AWS-SES-simple-mail-forward/blob/master/mail_forward_policy.json. -The relevant files have been committed to our git as ``configuration/mail_forward.js`` for the Lambda's code, and as ``configuration/mail_forward_policy.json`` for the security policy for the IAM role used for the Lambda. \ No newline at end of file +The relevant files have been committed to our git as ``configuration/mail_forward.js`` for the Lambda's code, and as ``configuration/mail_forward_policy.json`` for the security policy for the IAM role used for the Lambda. + +## Changing the List of Recipients + +Go to [https://eu-west-1.console.aws.amazon.com/lambda/home?region=eu-west-1#/functions/email-forward?tab=configuration](https://eu-west-1.console.aws.amazon.com/lambda/home?region=eu-west-1#/functions/email-forward?tab=configuration) and edit the ``to_address`` environment variable accordingly. \ No newline at end of file