The pain of sending email
Friday, January 21st, 2011Last night I decided to finally try and understand why some of the emails I was sending was getting caught in spam filters, particularly Yahoo and Hotmail. So it began.
#0 Read this. Get the basics.
#1 To test everything out, send yourself an email to a GMail account. When viewing the message, click the drop down and click “View Original”. From there you will be able to see the return-path and comments on the SPF.
#2
Make sure the return-path is set correctly in your code. This return-path will be used to do the reverse ptr lookup. In PHP Pear Mail that meant:
$mail =& Mail::factory('mail', array('Return-Path' => sprintf("-f %s", '[email protected]')));
#2
Read this. You need to request your hosting provider, in my case ServerBeach, to update your IPs SPF record.
Then the txt spf record needs to be updated to allow permit the server IP:
v=spf1 ip4:11.11.111.11 include:_spf.google.com ~all
#3
Setting up DKIM is hard. Read this. I’m using Exim4 and by default DKIM support is built in. To do it read this. But you’ll quickly realize that won’t work on etch! So you need to upgrade to Lenny and then make sure the lenny backports are on, because you need to go to exim 4.7+
# Main
deb http://http.us.debian.org/debian/ stable main non-free contrib
# Source
deb-src http://http.us.debian.org/debian/ stable main non-free contrib
# Security
deb http://security.debian.org/ stable/updates main contrib non-free
# backports for lenny
deb http://backports.debian.org/debian-backports lenny-backports main
So now install the backports version of exim after you’ve upgraded Debian to Lenny:
apt-get -t lenny-backports install exim4
Basically create the keys in the exim config directories /etc/exim4/:
openssl genrsa -out dkim.private.key 768
openssl rsa -in dkim.private.key -out dkim.public.key -pubout -outform PEM
Then update the file exim4.conf.template:
Make sure the dkim_private_key is to a fully qualified path
driver = smtp
dkim_domain = example.com
dkim_selector = x
dkim_private_key = /etc/exim4/dkim.private.key
dkim_canon = relaxed
Then update DNS with the txt entry and it should work. Just remember George you can’t do this in etch, you need to be in lenny and using exim > 4.70.

