PostfixIn most cases Sendmail is the default MTA (Mail Transfer Agent) for many systems (like with CentOS), it can however be hard to configure or maintain (although it has improved over the last years).

I myself prefer to use postfix for various reasons.

Postfix describes itself as “Postfix attempts to be fast, easy to administer, and secure. The outside has a definite Sendmail-ish flavor, but the inside is completely different.”

Postfix can be easily installed and configured, just follow the steps ahead.


First, before we install Postfix, we need to make sure all the DNS is in place.

It’s important that the DNS for your mail server’s host, resolves back to itself. Resolving a host is often used by systems to calculate the SPAM probability of the mail they receive (when it doesn’t resolve back).

An example of properly setup DNS:

Setup the DNS for mail.yourdomain.com, to point towards an IP address you’ve picked (Doesn’t matter if it’s with your registrar, in a zonefile, etcetera).

Make sure to setup the REVERSE DNS if you can.

TIP
If you need to bind the ‘extra’ IP address to your server, just create an alias of eth0 for instance:

Install Postfix

Use the power of YUM, install the postfix RPM.

Edit the configuration file for postfix:

Be sure to at least configure the following:

  • the fully-qualified server name (mail.mydomain.com):
    myhostname = mail.mydomain.com
  • the path of the primary domain (mydomain.com):
    mydomain = mydomain.com
  • the path of the fully-qualified domain (mail.mydomain.com) or the path of the primary domain (mydomain..com):
    myorigin = $myhostname
    # or
    myorigin = $mydomain

Make sure postfix starts when your server reboots and make sure sendmail doesn’t! Also, time to start Postfix!

Your server should be running postfix by now!

Now, to make testing bit easier edit /etc/aliases and change root (All the way down, don’t forget to remove the #) to an external address with for instance gmail.com.

Setup SPF records

SPF is strongly recommended to use if you want to increase the chance that the mail send from your mailserver will actually arrive at the location you send it. If you don’t plan to use this mailserver for sending outgoing mail, then skip this part.

SPF is the Sender Policy Framework, you can use a SPF tool to create the appropriate SPF record for your domain.

Once you’ve got your SPF record created, you need to add it to the DNS of your domain as a TXT record.

MX Record

Don’t forget to change the MX record for your domain to your new mailserver address, mail.mydomain.com!

All set!

Your mailserver is now fully working and should accept mail for your aliases. I won’t discuss setting up antivirus, antispam and things like that yet, perhaps in a future post.

Testing the server

mail.mydomain.tld responds by saying hello back to remotehost.domain.com by doing a reverse dns lookup. This helps prevent host spoofing (which is exactly what SPF helps with!).

The server responds that the email address my@test.com is acceptable and issues an ok.

The server recognizes mylocaluser as a valid system user. If the recipient does not exist, the server would issue a user unknown response.

Now, fire up your browser and login to the gmail account you setup, you should have a new mail (NOT in your SPAM folder). Open it and click “Show original”. Below you can see my test (with some hosts changed) which demonstrates that Google uses SPF.

It’s as simple as that!

Share and Enjoy:
  • Digg
  • del.icio.us
  • Furl
  • Slashdot
  • Spurl
  • StumbleUpon
  • Technorati