fariazz
By:
fariazz

Missing tutorial: setting up a mail server

December 31, 2012 30.3k views
I'd like to thank you for the tutorials you have so far, they've been very helpful in setting up my machine. An important aspect that is missing in my opinion is a tutorial on how to setup a mail server, configure postfix, etc. Since Google Apps is not free anymore this becomes a more important issue.
28 Answers
Question on this subject, to setup postfix you have to enter a domain like "mail.example.com". If my domain is example.com, how do I setup mail.example.com? I mean do I add a "A record" in the control panel? what do I write for IP? or does it need to be another kind of record, like CNAME record.

Do I add mail.example.com as a virtual host in Apache? what config should that have?
Mail records are handled in DNS by the MX record.

Which means you do not need a mail.example.com subdomain.

You would just need to add an MX record to your domain that points to the IP of your server where your MTA (postfix) is running.

The most common way that is setup is by adding an MX record that points to mail.example.com.

Then adding an A record for mail.example.com that points to your servers IP, this way if you happen to move your email somewhere else the MX record doesn't need to be updated, just the A record for mail.example.com.
  • What if the question isn't one of need with respect to mail.example.com? Is there any way to establish an MX record for mail.example.com if that's simply what is desirable? At this point, it seems like digitalocean assumes @ (example.com) for me for the host name and only allows specification of the destination. Is that correct? Is there any way to establish an MX record for anything apart from @?

Thanks raiyu. What number should I enter in the "priority" field for the mx record?
10 is a standard for primary mail server, 20 can be used for backup. The lower the number the bigger the preference. So a priority of 1 is the best.
Thanks guys for the help.

I've installed postfix as per this guide http://www.pixelinx.com/2010/10/creating-a-mail-server-on-ubuntu-using-postfix-courier-ssltls-spamassassin-clamav-and-amavis/

But I think I'm running into issues with iptables, which I installed following your tutorial.

What rules should I have in iptables to allow email?

my current rules are these, and I'm not able to check mail:

Chain INPUT (policy ACCEPT)
target prot opt source destination
fail2ban-ssh tcp -- anywhere anywhere multiport dports 16060
fail2ban-ssh tcp -- anywhere anywhere multiport dports 16060
ACCEPT all -- anywhere anywhere ctstate RELATED,ESTABLISHED
ACCEPT tcp -- anywhere anywhere tcp dpt:16060
ACCEPT tcp -- anywhere anywhere tcp dpt:http
ACCEPT tcp -- anywhere anywhere tcp dpt:imaps state NEW,ESTABLISHED
ACCEPT tcp -- anywhere anywhere tcp dpt:smtp state NEW,ESTABLISHED
DROP all -- anywhere anywhere

Chain FORWARD (policy ACCEPT)
target prot opt source destination

Chain OUTPUT (policy ACCEPT)
target prot opt source destination
ACCEPT tcp -- anywhere anywhere tcp spt:imaps state ESTABLISHED
ACCEPT tcp -- anywhere anywhere tcp spt:smtp state ESTABLISHED

Chain fail2ban-ssh (2 references)
target prot opt source destination
RETURN all -- anywhere anywhere
RETURN all -- anywhere anywhere
I've fixed this, my iptables firewall.

Chain INPUT (policy ACCEPT)
target prot opt source destination
fail2ban-ssh tcp -- anywhere anywhere multiport dports 16060
fail2ban-ssh tcp -- anywhere anywhere multiport dports 16060
ACCEPT all -- anywhere anywhere ctstate RELATED,ESTABLISHED
ACCEPT tcp -- anywhere anywhere tcp dpt:16060
ACCEPT tcp -- anywhere anywhere tcp dpt:http
ACCEPT tcp -- anywhere anywhere tcp dpt:https
ACCEPT tcp -- anywhere anywhere tcp dpt:imap2 state NEW,ESTABLISHED
ACCEPT tcp -- anywhere anywhere tcp dpt:imaps state NEW,ESTABLISHED
ACCEPT all -- anywhere anywhere
ACCEPT tcp -- anywhere anywhere tcp dpt:smtp state NEW,ESTABLISHED
DROP all -- anywhere anywhere

Chain FORWARD (policy ACCEPT)
target prot opt source destination

Chain OUTPUT (policy ACCEPT)
target prot opt source destination
ACCEPT tcp -- anywhere anywhere tcp spt:imaps state ESTABLISHED
ACCEPT tcp -- anywhere anywhere tcp spt:smtp state ESTABLISHED
ACCEPT tcp -- anywhere anywhere tcp spt:imap2 state ESTABLISHED
ACCEPT all -- anywhere anywhere

Chain fail2ban-ssh (2 references)
target prot opt source destination
RETURN all -- anywhere anywhere
RETURN all -- anywhere anywhere

Still can't receive email, get this in mail.log when I send myself an email from a gmail account, and the email bounces back

Jan 11 21:32:12 localhost postfix/smtpd[12962]: NOQUEUE: reject: RCPT from mail-ob0-f178.google.com[209.85.214.178]: 554 5.7.1 : Sender address rejected: Access denied; from= to= proto=ESMTP helo=
Jan 11 21:32:12 localhost postfix/smtpd[12962]: disconnect from mail-ob0-f178.google.com[209.85.214.178]
Nevermind, sorted it out using this http://ubuntuforums.org/showthread.php?t=1277902
What was missing from the previous config you posted that you fixed up?
In smtpd_recipient_restrictions I replaced "reject" by "reject _unauth_destination"
I get "450 4.7.1 Client host rejected: cannot find your reverse hostname" when email is send.
What have I wrong configured? Please help.

I have:
MX record mail.example.com.
A record mail MyIP

$ sudo dpkg-reconfigure postfix
setting synchronous mail queue updates: false
setting myorigin
setting destinations: localhost, localhost.localdomain, , localhost
setting relayhost:
setting mynetworks: mail.example.com
setting mailbox_size_limit: 0
setting recipient_delimiter: +
setting inet_interfaces: all
setting inet_protocols: all

Thanks
Often times when sending email as a spam prevention measure the receiving host will lookup your servers rDNS for it's IP. This is the reverse record of DNS, which maps your IP to a hostname, instead of the usual domain name to a record.

To fix this just rename your virtual server to a fully qualified domain name, one that matches a domain on the server and we will automatically create an rDNS record for you and this issue should be resolved.
Hello there. So as I think the answer has been missed somehow. Is there a tutorial planed? This is the only thing I seem to be missing. And I can not live without my e-maill ;-)
We have a couple up :

https://www.digitalocean.com/community/articles/how-to-install-and-setup-postfix-on-ubuntu-12-04

https://www.digitalocean.com/community/articles/how-to-install-postfix-on-centos-6

Thanks
by Etel Sverdlov
This tutorial explains how to install postfix and cyrus with yum, how to configure postfix, how to configure cyrus, how to install mailx, and how to send a test email. Postfix is free open source Mail Transfer Agent which works to route and deliver email.This tutorial should help you set up a mail server on a centos droplet.
Nice one, So far I got "postfit" installed. But I am going to pull my hair out soon lol. I Can not for the life of me get a mail server like dovecot up and running. Every bit goolgeing I do ends in a road block of some kind. I Did log on to IRC yesterday and somebody there said I was going to have a hard time of it. They was right. Worst part is., As of right now I am with out e-mail as my domain name is pointed to my droplet. So do you happen to have a noobs guild tutorial to getting some sort of working imap or pop3 3 server that works with your ubuntu 12.10 32 bit droplet images? Hope to hear from somebody soon

Thanks

Pete
Have you checked out this tutorial:
https://www.digitalocean.com/community/articles/how-to-install-postfix-on-centos-6

Also Pete I hear your frustration and unfortunately its part of the process when working with mail servers. There are alot of moving parts and a lot of things to configure, many of which aren't essential but it drowns out the ones that are with a lot of noise.

We are hopefully going to start working on application images this week and start launching them next and setting up a simple mail server where we provide information in the server's MOTD how to modify it to use your own domains/emails is definitely one that we need to provide to make people's lives easier.
by Etel Sverdlov
This tutorial explains how to install postfix and cyrus with yum, how to configure postfix, how to configure cyrus, how to install mailx, and how to send a test email. Postfix is free open source Mail Transfer Agent which works to route and deliver email.This tutorial should help you set up a mail server on a centos droplet.
OK, I give up. I haver now spend 3 days stuck on this one silly issue. I have tried 5 diffident tutorials to get this working, And every time I get too the end. It never works. Seems so silly to be so hard. The rest of linux software is so easy to install and setup. I have never hit such a road block ever. What are the chances of getting one of the admin team here at Digital Ocean to install and config it for me?
What is the full suite of applications that you are install for your MTA?

Have you tried postfix + cyrus ?
This is what I followed

http://www.pixelinx.com/2010/10/creating-a-mail-server-on-ubuntu-using-postfix-courier-ssltls-spamassassin-clamav-and-amavis/

Every other guide I tried was not up to date. But this last one seems to work out. But Alas, No joy ;(

I Did look at cyrus, but the websites has very poor info about installing it. so no. I have not tried cyrus. And at this point. I am not going to lol. My head is wreaked.
In my experience cyrus has been the easier way out.

But in most cases setting up a proper MTA config the first time is usually brain wrecking =]

Maybe take a day off clear your head and try again from a new tutorial:
https://www.digitalocean.com/community/articles/how-to-install-postfix-on-centos-6

Usually whenever I deal with a really challenging programming issue I need to take a few hours off from thinking about it and then solution pops up in my head.
by Etel Sverdlov
This tutorial explains how to install postfix and cyrus with yum, how to configure postfix, how to configure cyrus, how to install mailx, and how to send a test email. Postfix is free open source Mail Transfer Agent which works to route and deliver email.This tutorial should help you set up a mail server on a centos droplet.
Yes, I Did try it. But I hit a road block at "sudo yum install cyrus-sasl" as there is no package for "cyrus-sasl" on ubuntu 12.10

lol, This is really silly. Linux has been the server system of choice for years. But how is it nobody has come up with an easy way to install a mail server hahahahah
# apt-get install libsasl2-2 sasl2-bin libsasl2-modules cyrus-imapd

Assuming you want Cyrus for imapd (recommended over pop3).

Also a couple of good overviews:
https://help.ubuntu.com/community/Postfix
https://help.ubuntu.com/11.10/serverguide/postfix.html
Good tutorial that worked for me (up to the horde installation part): http://www.exratione.com/2012/05/a-mailserver-on-ubuntu-1204-postfix-dovecot-mysql/
Guys, untill the admins decide to make a tutorial for this part you can use this
http://www.pixelinx.com/2010/10/creating-a-mail-server-on-ubuntu-using-postfix-courier-ssltls-spamassassin-clamav-and-amavis/
It worked for me, hope this helps anibody that's struggling like me.
I was able to get my mail server sending mail. I'm running all of the mailboxes on another providers server so I don't have to deal with that. However all of my messages are going to the spam folder in gmail and yahoo. Has anyone had this issue?
Have an SPF record? Setup Domain keys? Reverse-lookup working?
this seem mail server sending mail have many issues
@ngoctien333: What kind of issues are experiencing?
Have another answer? Share your knowledge.