While I'm happily using mailgun for mail sending (after much frustration I threw in the towel trying to integrate DKIM packages with Postfix to get my outgoing emails secured) I was certain that I could at least have my mail server handle mail-forwarding for my multiple domains, and while that proved to be fairly straightforward I then tumbled down a rabbit-hole trying to get Postfix to pipe certain emails to a node.js script for processing.
- Here are the steps you'll need to take:
- Set up your A and MX records for your domain, the A record @ pointing to the IP address of the server you’re going to be receiving emails on and MX with the hostname @ and the value 10 mail.your-domain-name
If your mail server is not the same as your primary A record, simply create an additional A record mail pointing to the correct IP address.
- sudo apt-get install postfix
Select "Internet Site" and enter your-domain-name (fully qualified)
- sudo vi /etc/postfix/main.cf
- Add mail.your-domain-name to the list of mydestination values
virtual_alias_domains = hash:/etc/postfix/virtual_domains virtual_alias_maps = hash:/etc/postfix/virtualto the end of the file
- sudo vi /etc/aliases
curl_email: "|curl --data-binary @- http://your-domain-name/email"
- sudo newaliases
- sudo vi /etc/postfix/virtual_domains
example.net #domain example.com #domain your-domain-name #domain(the #domain fields suppress warnings)
- sudo postmap /etc/postfix/virtual_domains
- sudo vi /etc/postfix/virtual
info@your-domain-name firstname.lastname@example.org everyone@your-domain-name email@example.com firstname.lastname@example.org email_processor@your-domain-name curl_email@localhost @your-domain-name email@example.com firstname.lastname@example.org email@example.com
- sudo postmap /etc/postfix/virtual
- sudo /etc/init.d/postfix reload
You should be able to find your postfix logs at /var/log/mail.log. Good luck!