Friday, April 18, 2014

setup postfix

# yum install postfix

If you using sendmail before, please remove it to avoid smtp port taken up by sendmail
# yum remove sendmail

you can check and configure which to use for the main MTA
# alternatives --config mta

Open and edit the postfix config 
# vim /etc/postfix/main.cf.
Normally postfix server could be used directly out of the box. However to make sure you have more control on it, a few tuning needed to be done.
In /etc/postfix/main.cf , you need to change myhostnam, mydomain and myorigin. for example,

     myhostname=mail.gabby.com
 
     mydomain=gabby.com #Normally this will need not to be done, as the postfix server will use your system domain name.
 
     myorigin=$myhostname

Let say if your $myhostname is mail.gabby.com, your email sending from this host will have gab@mail.gabby.com appear in the email 'From' if you're logging in as gab. If you're logging in as root, the recipient will get an email from root@mail.gabby.com


Make sure also

     mydestination=localhost, localhost.$mydomain, $myhostname

this is to tell the postfix, if it receives an email end with @localhost, @localhost.offgamers.lan, @my-proxy.offgamers.lan, he will not deliver that email 'out' from that box, and it will deliver locally which mean no 'sending' will be done. This is important to prevent infinite loop of the email sent out from this box.


     mynetworks_style=host
     relay_domains=
to prevent this box from receiving other email server to relay out emails and it will not sending relay email to other email server as well. This help stopping this box become a relay zombie for spamming.


Becareful that if that mail server is used by REMOTE client to post mail, then the mynetworks_style need to put as

     mynetworks_style=subnet
     inet_interfaces=all
if the REMOTE client is in the same subnet, to surf for as a small LAN mail server for the subnet.


You also need to change /etc/syslog.conf , from
mail.*     -/var/log/maillog
to
mail.*     /var/log/maillog
to prevent Asynchronous log writing as this email server only used by the local box hence the traffic is not heavy till need to use an Asynchronous log writing. That is only vital for a production mail server.Restart syslogd to have the result updated

# /etc/init.d/syslog restart

If you are using hostname same with the email, your postfix will send to gab locally instead of sending to gab@mail.gabby.com
to solve this, you need to remove the $myhostname from mydestionation

     mydestination=localhost, localhost.$mydomain

but by doing this, all your root email will not be send to you locally and will send out to root@mail.gabby.com. in order to deliver the email locally for root users you need set up virtual aliases as follow:

# vim /etc/postfix/main.cf
     
     virtual_alias_maps = hash:/etc/postfix/virtual

# vim /etc/postfix/virtual

     root     root@localhost

after done, execute this command

# postmap /etc/postfix/virtual

No comments:

Post a Comment