Using postfix with SPF to avoid being flagged as spam

On thing important when you have you own linux box to host a web server is the ability to send email as many services are relying on this.

Often mail server receiving these email will flag them as spam because of improper configuration. Here is how I have been able to overcome this issue:

  1. Make sure you have a domain or subdomain pointing to you server IP that you can use as a tool domain. In this example I will user
  2. So I have a A record with pointing to the server IP
  3. Now edit the file configuration /etc/postfix/
  4. Make sure the hostname file looks like this: myhostname =
  5. Also make sure this line is like this: inet_protocols = ipv4 (this will ensure the postfix is only using ipv4 and ipv6 to send out the emails).
  6. Restart Postfix: /etc/init.d/postfix restart
  7. Now create a SPF record in you DNS to allow sending email from this IP. Create a TXT record and the content should be: v=spf1 -all where is your server IP address. The txt should be on (the domain you have used in step 1).

Now you should be all set. You can test it by having the server send an email, on my side I use WordPress recover password to test it against google server. The mail should not go to spam anymore. Check the original version of the mail (in gmail, dropdown next to reply button > show original). This will help you to troubleshoot if the email still goes to spam.

Leave Your Response

* Name, Email, Comment are Required