This script allows you to set up a simple email forwarding server using SendGrid's Inbound Parse. You can configure several domains and user names, each forwarding to several emails addresses.
You can configure the mailhandler by placing a application.yml
file in the same directory as your mailhandler.jar
.
Mailhandler uses an SMTP server of your choice to send the messages. The default is localhost:8025
. You can configure it as follows:
mail:
smtp:
host: localhost
post: 8025
user: myuser
pass: mypass
transport: TLS
You domains can also be configured in the same file. To forward emails received at [email protected]
to [email protected]
and [email protected]
, you can use the following configuration:
mail:
domains:
- domain: example.com
mappings:
- admin:
- [email protected]
- [email protected]
You can test the application by creating a local tunning using ngrok.
- Install ngrok - on macOS with homebrew:
brew cask install ngrok
- Create a tunnel to your local instance (by default it's on port
8181
):
ngrok http 8181
-
In the SendGrid dashboard, go to Settings -> Inbound Parse and configure your domain to point the url you received from ngrok, e.g.
https://a93b4408.ngrok.io
. Make sure you check "Spam check" but not "Send raw". Make sure your domain has the MX record configured to point to SendGrid's servers. -
Configure your domain in
src/main/resources/application.yml
-
Send an email to the email you configured, ngrok will allow you to replay the request as often as you want through the web interface running on port 4040.