Last Updated: February 25, 2016
·
685
· anrid

Sending emails via your web app

A short checklist to help ensure the emails you send via your web app don't end up in the recipient's spam folder, or get rejected outright:

First off, the SPF record. I'm using binumi.com as an example:

[root]# dig binumi.com TXT
;; ANSWER SECTION:
binumi.com.     60  IN  TXT "google-site-verification=xxx"
binumi.com.     60  IN  TXT "v=spf1 a mx ptr include:_spf.google.com ~all"

[root]# dig binumi.com SPF    
;; ANSWER SECTION:
binumi.com.     60  IN  SPF "v=spf1 a mx ptr include:_spf.google.com ~all"

Then a proper PTR record. A Reverse DNS entry pointing back to your server.

[root]# dig binumi.com PTR

;; ANSWER SECTION:
binumi.com.     300 IN  PTR binumi.com.

If you're using postfix, make sure to set your domain:

[root]# nano /etc/postfix/main.cf 

# find 'myorigin' (CTRL-W)
# The mydomain parameter specifies the local internet domain name...
#
mydomain = binumi.com

# SENDING MAIL
#
# The myorigin parameter specifies the domain that locally-posted 
# mail appears to come from...
#
myorigin = $mydomain

This should be enough to have your emails pass the SPF check on Gmail:

Received-SPF: pass (google.com: domain of thedude@binumi.com designates 54.251.115.86 as permitted sender) client-ip=54.251.115.86;
Authentication-Results: mx.google.com;
   spf=pass (google.com: domain of thedude@binumi.com designates 54.251.115.86 as permitted sender) smtp.mail=thedude@binumi.com