How to set up postfix mail

  linux

First set up Nginx to recognize your domain, etc. mydomain.example.com , assume this server is called gateway, so gateway.mydomain.example.com

sudo nano /etc/hosts

127.0.0.1       localhost
::1             localhost ip6-localhost ip6-loopback
ff02::1         ip6-allnodes
ff02::2         ip6-allrouters

127.0.1.1       mydomain.example.com gateway gateway.mydomain.example.com

Install postfix:

sudo apt-get update; sudo apt-get install postfix

Internest Site → gateway.mydomain.example.com → 

# Update your /etc/mailname file with your main domain name that will show up in your outgoing email headers
gateway.mydomain.example.com

Edit:

/etc/postfix/main.cf

At the bottom of the file, add:

# ALAN - turn OFF unknown local recipient rejects, set empty value
local_recipient_maps =

Make sure you also allow email to these domains, have the mydestination= entry in the main.cf file. Example:

mydestination = localhost.localdomain, localhost, gateway.mydomain.example.com, gatway, mydomain.example.com

Since you’ve listed your domains in mydestination=, then make sure you DO NOT list your domains in the virtual_alias_domains line. Comment it out

# make sure this is COMMENTED OUT, if it even exists in your config file
# virtual_alias_domains = mydomain1.com myotherdomain.org something.com

Allow smtp connections from outside:

# Allow outside connections: edit /etc/postfix/main.cf
# Comment the loopback-only entry, add another entry and allow "all":

# inet_interfaces = loopback-only
inet_interfaces = all

Finishing up:

newaliases

# restart
/etc/init.d/postfix restart
 
# watch the log
sudo tail -f /var/log/mail.log