Skip to content

Lambda function to forward mails from AWS SES to Slack/Mattermost

License

Notifications You must be signed in to change notification settings

int128/ses-to-slack

Repository files navigation

SES to Slack

This is an AWS Lambda function to forward mails from SES to Slack, based on the Serverless framework.

How it works

Mail Server
↓ SMTP
AWS SES
↓ Publish
AWS SNS
↓ Subscribe
AWS Lambda
↓ HTTP(S)
Slack Incoming Webhook

Getting Started

Deploy a Lambda function.

# Setup credentials
npm run serverless -- config credentials -p aws -k IAM_KEY -s IAM_SECRET

# Deploy
npm install
npm run deploy

Open the AWS Management Console and do following steps:

  1. Open Lambda and Check ARN of the function, like arn:aws:lambda:ap-northeast-1:***:function:ses-to-slack-dev-handle.
  2. Add an environment variable on the function:
    • WEBHOOK: URL of Slack Incoming Webhook (Mandatory)
    • WEBHOOK_USERNAME: Username for Incoming Webhook request (Optional)
    • WEBHOOK_ICON_EMOJI: Icon for Incoming Webhook request (Optional)
    • WEBHOOK_HOST_HEADER: Host header for Incoming Webhook request (Optional)
  3. Open SNS and create a topic.
  4. Create a subscription on the topic:
    • Protocol: AWS Lambda.
    • Endpoint: ARN of the Lambda function.
  5. Open SES and make sure your domain has been verified.
  6. Create a rule set with the following action:
    • SNS topic: ARN of the SNS topic.
    • Encoding: UTF-8

Sending to Mattermost

Mattermost is a Slack alternative. You can send mails to a Mattermost channel as well.

  1. Create an Incoming Webhook on a Mattermost team.
  2. Set the WEBHOOK environment variable.

If the instance is protected by the security group, you can send mails via VPC. For example,

Mail Server
↓ SMTP
AWS SES
↓ Publish
AWS SNS
↓ Subscribe
AWS Lambda
↓ ENI
↓ VPC
↓ ENI
AWS EC2

If a reverse proxy exists and requires Host header, you can specify the WEBHOOK_HOST_HEADER environment variable.

Caveat

SNS can receive mails that are 150kB or less. Larger mails will bounce.

Contributions

Feel free to open an issue or pull request.

About

Lambda function to forward mails from AWS SES to Slack/Mattermost

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published