Best practice for mailserver setup

Posted September 11, 2014 9.2k views


I followed an tutorial about setting up a mailserver.

I have setup the following DNS records for my domain in DO`s DNS manager:
Mx 5
Txt @ “v=spf1 mx -all”

This should setup mail.mydomain as mailserver right? I am using virtualmin which has postfix mailserver running.

This is not (yet) working for this domain, but I got it working on another domain, so that does not really matter for now. What matters is that i`m wondering if this is the ideal configuration for a mailserver. Am I not missing a few backup TXT or Mx records?

What are the best practices, DNS records or postfix tips to setup mailserver for reliable e-mail sending and receiving? Also, what are the pitfalls of my setup? I use dovecot for IMAP mail sending and receiving.

I`m totally new on this so hopefully someone can help.

What is essential that I can setup a mailserver like, or , something like that.

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
1 answer

With this configuration you are able to send mail for all servers in the world :)

remember that your vps name need to be the same of your mx name:
When you have your vps name as your mx record name, your PTR record on DO dns servers answer with “”, this is essentials to your server work perfectly.

  • Hi, Thanks!

    “With this configuration you are able to send mail for all servers in the world :)”
    What exactly do you mean? That anyone can sent mail via my server, or that this is OK?

    My VPSs name is not the name of my mail records.. My VPS name is a nonregistred domainname. Within this I have setup virtualmin with 2 domains. These domains I have added to DigitalOcean DNS and for these domains I have setup Is that wrong?

    Because it is not working.. I can sent mails from rouncube, but not receive. Sending an e-mail to the mailadress on this server gives a error, something about relay and another said something about mailserver looping back to itself.

    I have setup another VPS where this is actually working. I Cloned the VPS to a new droplet and it is not working now. The other VPS name is an existing domainname, for this VPS it is nog existing. Will that be my problem?

    And how should my DNS records if my VPSs name is and there are 2 domains on this VPS: and Where and how (what DNS records) would I set up my mailserver?

  • Btw: the relay error is this: “Relay access denied”

    What now? How can I get this working.

    Something else: my website is working fine. So the DNS is resolving to the right domain. Only mail.domain is not working..

    Thanks a lot in advance.

  • Well, if you get this error “Relay access denied” your server was protected to anyone send mail to anywhere.
    But, if this doesnt work to your domain (that you want work, is because that domain isn`t listed on domain on postfix configuration.

    Another think is, if you have, 2 domains, like

    and MX record are and your SPF record point to
    you vps name need to be because this apoint you PTR record to that name.

  • Ok, I understand. But what if I want to use for and for, on one VPS?

    You said the PTR record has to be the VPSs name in order to have this work properly. How would I setup the use of 2 domains with own mailservers in this case?

  • Hi, I have created a new question since more and more questions popped up. See : , I hope you have an answer to this. Many thanks anyways!