cloudflare-discord-mailing is a worker that allows you to see and respond to E-Mails in Discord using Cloudflare Workers + Route to Workers + Mailchannels.
Create a Discord application, add a bot to it in the Bot tab and invite the bot to your server.
Clone this repository and then get wrangler and the Discord developer panel ready, because we'll need to add some secrets.
-
Deploy your worker, so we can add secrets to it. Use
npm run deploy
orwrangler publish
. -
Do
wrangler secret put CHANNEL_ID
and enter your Discord channel that emails will be sent to. Make sure your bot has the view channels, send messages, embed links and attach files permissions! -
Now go to your developer panel and copy your public key. Do
wrangler secret put PUBLIC_KEY
and enter it. -
Final step is getting your bot token, by going to the Bot tab. Then reset your token to get your api token (might require 2FA). Proceed to put into wrangler with
wrangler secret put TOKEN
and then entering it. -
Now that you've done the worker setup, set your workers url as the INTERACTIONS ENDPOINT URL in the Discord General Information tab of your application. (the URL will look something like
https://cloudflare-discord-mailing.<your-name>.workers.dev
) -
Finally, go to your zone's Email Workers settings and create a custom address (or catch-all) that routes to your worker.
https://mailchannels.zendesk.com/hc/en-us/articles/200262610-Set-up-SPF-Records
https://mailchannels.zendesk.com/hc/en-us/articles/7122849237389
You can use the following commands to set the required variables:
wrangler secret put DKIM_DOMAIN
wrangler secret put DKIM_SELECTOR
wrangler secret put DKIM_PRIVATE_KEY
You can modify src/routing.ts
for more advanced routing.
- All attachments are ignored
- Characters past 4,096 are removed (embed description length limit)
- Everyone can use the reply button
This project is using the postal-mime library which is released under the AGPL license. Due to the license, this project must also be released under AGPL.
If you find any decent email parsing library alternative that works in workers and has a more sane license, please let us know and open an issue.