This example shows how to receive an email header with SES, trigger a lambda function, process headers or accept or reject emails.
- Postprocess of email header.
- accept or reject emails
- Create a SES verified Domain but do not setup the "Rule Set"
- if you change the region check if SES receiving exists in your region
- if you change the function names you will need to update the normalized function name used in the resource section - e.g. processacceptreject => ProcessacceptrejectLambdaFunction
In order to deploy the example, simply run:
serverless deploy
The output should look similar to:
Serverless: Packaging service...
Serverless: Excluding development dependencies...
Serverless: Uploading CloudFormation file to S3...
Serverless: Uploading artifacts...
Serverless: Uploading service .zip file to S3 (2.69 KB)...
Serverless: Validating template...
Serverless: Updating Stack...
Serverless: Checking Stack update progress...
........................
Serverless: Stack update finished...
Service Information
service: aws-node-ses-receive-email-header
stage: dev
region: eu-west-1
stack: aws-node-ses-receive-email-header-dev
api keys:
None
endpoints:
None
functions:
processheader: aws-node-ses-receive-email-header-dev-processheader
- Open the Amazon SES console at https://console.aws.amazon.com/ses/
- In the navigation pane, under Email Receiving, choose Rule Sets.
- Choose Create a Receipt Rule.
- On the Recipients page, choose Next Step. (Without a adding any recipients, Amazon SES applies this rule to all recipients)
- For Add action, choose lambda.
- For Lambda function, choose the lambda function with the name aws-node-ses-receive-email-header-dev-processheader you defined in
serverless.yml
- Invocation type choose Event
- Choose Next Step
- On the Rule Details page, for Rule name, type my-rule. Select the check box next to Enabled, and then choose Next Step.
- On the Review page, choose Create Rule.
Schritte 1-5 sind identisch dann:
- For Lambda function, choose the lambda function with the name aws-node-ses-receive-email-header-dev-processacceptreject you defined in
serverless.yml
- Invocation type choose RequestResponse (Lambda function will be called synchronously to control mail flow)
- Choose Next Step
- On the Rule Details page, for Rule name, type my-rule. Select the check box next to Enabled, and then choose Next Step.
- On the Review page, choose Create Rule.
Send a test email to the receipient.
serverless logs -t --function processheader
START RequestId: eada06fc-c76a-11a8-bffd389a883292 Version: $LATEST
<date> <RequestId> { from: 'Tim Turbo <[email protected]>',
to: '[email protected]',
subject: 'Testsubject',
date: 'Thu, 4 Oct 2018 01:33:06 +0200' }
END RequestId: eada06fc-c76a-11a8-bffd389a883292
REPORT RequestId: eada06fc-c76a-11a8-bffd389a883292 Duration: 5.62 ms Billed Duration: 100 ms Memory Size: 1024 MB Max Memory Used: 19 MB