{"id":13394264,"url":"https://github.com/arithmetric/aws-lambda-ses-forwarder","last_synced_at":"2025-05-14T16:11:53.591Z","repository":{"id":39105424,"uuid":"45359947","full_name":"arithmetric/aws-lambda-ses-forwarder","owner":"arithmetric","description":"Serverless email forwarding using AWS Lambda and SES","archived":false,"fork":false,"pushed_at":"2025-01-11T15:55:51.000Z","size":146,"stargazers_count":1711,"open_issues_count":73,"forks_count":452,"subscribers_count":60,"default_branch":"master","last_synced_at":"2025-04-12T21:19:01.677Z","etag":null,"topics":["aws-lambda","aws-ses","email","email-forwarding"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/arithmetric.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE-MIT","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-11-01T22:21:06.000Z","updated_at":"2025-04-10T14:18:30.000Z","dependencies_parsed_at":"2024-01-14T08:27:58.584Z","dependency_job_id":"d05fa014-b4f6-4413-a01a-3b4040389f58","html_url":"https://github.com/arithmetric/aws-lambda-ses-forwarder","commit_stats":{"total_commits":117,"total_committers":21,"mean_commits":5.571428571428571,"dds":0.3846153846153846,"last_synced_commit":"6aa3fa49d1318c9090d8d0fee1f15c46ebb7eadf"},"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arithmetric%2Faws-lambda-ses-forwarder","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arithmetric%2Faws-lambda-ses-forwarder/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arithmetric%2Faws-lambda-ses-forwarder/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arithmetric%2Faws-lambda-ses-forwarder/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/arithmetric","download_url":"https://codeload.github.com/arithmetric/aws-lambda-ses-forwarder/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248631870,"owners_count":21136581,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["aws-lambda","aws-ses","email","email-forwarding"],"created_at":"2024-07-30T17:01:14.255Z","updated_at":"2025-04-12T21:19:05.972Z","avatar_url":"https://github.com/arithmetric.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# AWS Lambda SES Email Forwarder\n\n[![npm version](https://img.shields.io/npm/v/aws-lambda-ses-forwarder)](https://www.npmjs.com/package/aws-lambda-ses-forwarder)\n\nA Node.js script for AWS Lambda that uses the inbound/outbound capabilities of\nAWS Simple Email Service (SES) to run a \"serverless\" email forwarding service.\n\nInstead of setting up an email server on an EC2 instance to handle email\nredirects, use SES to receive email, and the included Lambda script to process\nit and send it on to the chosen destination.\n\n## Limitations\n\n- SES only allows sending email from addresses or domains that are verified.\nSince this script is meant to allow forwarding email from any sender, the\nmessage is modified to allow forwarding through SES and reflect the original\nsender. This script adds a Reply-To header with the original sender, but the\nFrom header is changed to display the original sender but to be sent from the\noriginal destination.\n\n  For example, if an email sent by `Jane Example \u003cjane@example.com\u003e` to\n  `info@example.com` is processed by this script, the From and Reply-To headers\n  will be set to:\n\n  ```\n  From: Jane Example at jane@example.com \u003cinfo@example.com\u003e\n  Reply-To: jane@example.com\n  ```\n\n  To override this behavior, set a verified fromEmail address\n  (e.g., noreply@example.com) in the `config` object and the header will look\n  like this.\n\n  ```\n  From: Jane Example \u003cnoreply@example.com\u003e\n  Reply-To: jane@example.com\n  ```\n\n- SES only allows receiving email sent to addresses within verified domains. For\nmore information, see:\nhttp://docs.aws.amazon.com/ses/latest/DeveloperGuide/verify-domains.html\n\n- SES only allows sending emails up to 10 MB in size (including attachments\nafter encoding). See:\nhttps://docs.aws.amazon.com/ses/latest/DeveloperGuide/limits.html\n\n- Initially SES users are in a sandbox environment that has a number of\nlimitations. See:\nhttp://docs.aws.amazon.com/ses/latest/DeveloperGuide/limits.html\n\n## Set Up\n\n1. Modify the values in the `config` object at the top of `index.js` to specify\nthe S3 bucket and object prefix for locating emails stored by SES. Also provide\nthe email forwarding mapping from original destinations to new destination.\n\n2. In AWS Lambda, add a new function and skip selecting a blueprint.\n\n - Name the function \"SesForwarder\" and optionally give it a description. Ensure\n Runtime is set to Node.js 22.x. (Node.js 18.x and 20.x can also be used.)\n\n - For the Lambda function code, either copy and paste the contents of\n `index.js` into the inline code editor or zip the contents of the repository\n and upload them directly or via S3.\n\n - Ensure Handler is set to `index.handler`.\n\n - For Role, choose \"Basic Execution Role\" under Create New Role. In the popup,\n give the role a name (e.g., `LambdaSesForwarder`). Configure the role policy to\n the following:\n ```\n {\n    \"Version\": \"2012-10-17\",\n    \"Statement\": [\n       {\n          \"Effect\": \"Allow\",\n          \"Action\": [\n             \"logs:CreateLogGroup\",\n             \"logs:CreateLogStream\",\n             \"logs:PutLogEvents\"\n          ],\n          \"Resource\": \"arn:aws:logs:*:*:*\"\n       },\n       {\n          \"Effect\": \"Allow\",\n          \"Action\": \"ses:SendRawEmail\",\n          \"Resource\": \"*\"\n       },\n       {\n          \"Effect\": \"Allow\",\n          \"Action\": [\n             \"s3:GetObject\",\n             \"s3:PutObject\"\n          ],\n          \"Resource\": \"arn:aws:s3:::S3-BUCKET-NAME/*\"\n       }\n    ]\n }\n ```\n\n - Configure the Memory and Timeout settings according to your use case. For\n   simple text emails, a memory limit of 128 MB and timeout of 10 seconds should\n   be sufficient. For emails with large attachments, a memory limit of 512 MB or\n   more and timeout of 30 seconds may be required.\n\n3. In AWS SES, verify the domains for which you want to receive and forward\nemail. Also configure the DNS MX record for these domains to point to the email\nreceiving (or inbound) SES endpoint. See [SES documentation](http://docs.aws.amazon.com/ses/latest/DeveloperGuide/regions.html#region-endpoints)\nfor the email receiving endpoints in each region.\n\n\n4. If you have the sandbox level of access to SES, then also verify any email\naddresses to which you want to forward email that are not on verified domains.\n\n5. If you have not configured inbound email handling, create a new Rule Set.\nOtherwise, you can use an existing one.\n\n6. Create a rule for handling email forwarding functionality.\n\n - On the Recipients configuration page, add any email addresses from which you\n want to forward email.\n\n - On the Actions configuration page, add an S3 action first and then an Lambda\n action.\n\n - For the S3 action: Create or choose an existing S3 bucket. Optionally, add an\n object key prefix. Leave Encrypt Message unchecked and SNS Topic set to [none].\n\n - For the Lambda action: Choose the SesForwarder Lambda function. Leave\n Invocation Type set to Event and SNS Topic set to [none].\n\n - Finish by naming the rule, ensuring it's enabled and that spam and virus\n checking are used.\n\n - If you get an error like \"Could not write to bucket\", follow step 7 before\n completing this one\n\n - If you are asked by SES to add permissions to access `lambda:InvokeFunction`,\n agree to it.\n\n7. The S3 bucket policy needs to be configured so that your IAM user has read\nand write access to the S3 bucket. When you set up the S3 action in SES, it may\nadd a bucket policy statement that denies all users other than root access to\nget objects. This causes access issues from the Lambda script, so you will\nlikely need to adjust the bucket policy statement with one like this:\n ```\n {\n    \"Version\": \"2012-10-17\",\n    \"Statement\": [\n       {\n          \"Sid\": \"GiveSESPermissionToWriteEmail\",\n          \"Effect\": \"Allow\",\n          \"Principal\": {\n             \"Service\": \"ses.amazonaws.com\"\n          },\n          \"Action\": \"s3:PutObject\",\n          \"Resource\": \"arn:aws:s3:::S3-BUCKET-NAME/*\",\n          \"Condition\": {\n             \"StringEquals\": {\n                \"aws:Referer\": \"AWS-ACCOUNT-ID\"\n             }\n          }\n       }\n    ]\n }\n ```\n\n8. Optionally set the S3 lifecycle for this bucket to delete/expire objects\nafter a few days to clean up the saved emails.\n\n## Extending\n\nBy loading aws-lambda-ses-forwarder as a module in a Lambda script, you can\noverride the default config settings, change the order in which to process\ntasks, and add functions as custom tasks.\n\nThe overrides object may have the following keys:\n- `config`: An object that defines the S3 storage location and mapping for\nemail forwarding.\n- `log`: A function that accepts log messages for reporting. By default, this is\nset to `console.log`.\n- `steps`: An array of functions that should be executed to process and forward\nthe email. See `index.js` for the default set of steps.\n\nSee [example](https://github.com/arithmetric/aws-lambda-ses-forwarder/tree/master/example)\nfor how to provide configuration as overrides.\n\n## Troubleshooting\n\nTest the configuration by sending emails to recipient addresses.\n\n- If you receive a bounce from AWS with the message `\"This message could not be\ndelivered due to a recipient error.\"`, then the rules could not be executed.\nCheck the configuration of the rules.\n\n- Check if you find an object associated with the message in the S3 bucket.\n\n- If your Lambda function encounters an error it will be logged\nin CloudWatch. Click on \"Logs\" in the CloudWatch menu, and you should find a log\ngroup for the Lambda function.\n\n## Credits\n\nBased on the work of @eleven41 and @mwhouser from:\nhttps://github.com/eleven41/aws-lambda-send-ses-email\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farithmetric%2Faws-lambda-ses-forwarder","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Farithmetric%2Faws-lambda-ses-forwarder","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farithmetric%2Faws-lambda-ses-forwarder/lists"}