diff --git a/README.md b/README.md index 3e3f219..601c159 100644 --- a/README.md +++ b/README.md @@ -57,7 +57,7 @@ The first command will build the source of your application. The second command ## Configure Receiving Rule in SES -**As mentioned above, you must already have an SES-verified domain in `us-east-1` before you can set up a Receiving Rule for that domain. See [AWS's SES documentation for details on verifying a domain](https://docs.aws.amazon.com/ses/latest/DeveloperGuide/receiving-email-getting-started-verify.html). +**As mentioned above, you must already have an SES-verified domain in `us-east-1` before you can set up a Receiving Rule for that domain. See [AWS's SES documentation for details on verifying a domain](https://docs.aws.amazon.com/ses/latest/DeveloperGuide/receiving-email-getting-started-verify.html).** After the Cloudformation application stack is successfully deployed, do the following: 1. Log into your AWS console and open your SES configuration home page diff --git a/src/handlers/ses-email-forwarding.js b/src/handlers/ses-email-forwarding.js index ac6d5c7..0dbe6f5 100644 --- a/src/handlers/ses-email-forwarding.js +++ b/src/handlers/ses-email-forwarding.js @@ -11,22 +11,14 @@ exports.handler = async (event, context) => { const file = await s3.getObject({Bucket: bucket, Key: object}).promise(); const parsed = await simpleParser(file.Body); + const bodyObject = makeBodyObject(parsed); const forwardingParams = { Destination: { ToAddresses: [process.env.FORWARD_ADDRESS] }, Message: { - Body: { - Html: { - Charset: "UTF-8", - Data: parsed.html - }, - Text: { - Charset: "UTF-8", - Data: parsed.text - } - }, + Body: bodyObject, Subject: { Charset: "UTF-8", Data: `to: ${parsed.to.text} sub: ${parsed.subject}` @@ -47,6 +39,28 @@ exports.handler = async (event, context) => { return; }; +function makeBodyObject(parsedEmail) { + let body = {}; + + if (parsedEmail.html) { + bodyObject = { + Html: { + Charset: "UTF-8", + Data: `${parsedEmail.html}` + } + }; + } else { + bodyObject = { + Text: { + Charset: "UTF-8", + Data: `${parsedEmail.text}` + } + }; + } + + return bodyObject; +} + async function sendEmail(params) { return new Promise ((resolve, reject) => { ses.sendEmail(params, function(err, data) {