[DigitalOcean] Setting up email forward with Postfix

It is quite a pain to setup email forwarding in DigitalOcean with not much experience in command line. Moreover, many tutorials online are outdated or didn’t provide right configuration. This is the guide to setup Postfix for email forwarding which I tested and tried many times.

Step 1: Install Postfix

Run this (in Ubuntu)

sudo apt-get update
sudo apt-get install postfix

Step 2: Choose ‘Internet Site’ for configuration

There will be pink screen for mail configuration pop after we have installed Postfix.

Follow these configurations:

  1. General type of mail configuration: Internet Site

  2. System mail name: example.com

  3. Root and postmaster mail recipient: <admin_user_name> e.g. root

  4. Other destinations for mail: example.com, localhost.example.com, localhost

  5. Force synchronous updates on mail queue?: No

  6. Local networks: 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128

  7. Mailbox size limit (bytes): 0

  8. Local address extension character: +

  9. Internet protocols to use: all

Step 3: Edit config file

Edit /etc/postfix/main.cf using command:

sudo nano /etc/postfix/main.cf

Add 2 more lines at the bottom:

virtual_alias_domains = example.com
virtual_alias_maps = hash:/etc/postfix/virtual

Then save.

Step 4: Setup forwarding email address

Add forwarding email addresses using the following command:

sudo nano /etc/postfix/virtual

At the beginning, this file should be empty. Then add 1 forward email addresses per line.

info@yourdomain.com youremail@gmail.com
sales@yourdomain.com youremail@gmail.com

Note: Hotmail usually block postfix forwarder (it might work at the first time, but it will fail to work after a while).

Solution for Hotmail:

  1. Set SMTP Relay (3rd party SMTP service) to send an email, but some SMTP service block sending domain that is not your own domain.
  2. Simple. Just create new gmail account and set auto-forward to hotmail.

We are almost there! Save and quit.

Step 5: Refresh Postfix

Run this command:

sudo postmap /etc/postfix/virtual
sudo service postfix restart

Test sending email to your forwarded address e.g. info@yourdomain.com. It should be forwarded to youremail@gmail.com !


Posted

in

by

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *