<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>All About LAMP &#187; Email</title>
	<atom:link href="http://allaboutlamp.com/category/email/feed/" rel="self" type="application/rss+xml" />
	<link>http://allaboutlamp.com</link>
	<description>Create web applications with Linux, Apache, MySQL, PHP and other open source technologies</description>
	<lastBuildDate>Sun, 08 Jan 2012 15:45:27 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>How to Prevent Web Server Emails from being Marked as SPAM</title>
		<link>http://allaboutlamp.com/2009/09/how-to-prevent-web-server-emails-from-being-marked-as-spam/</link>
		<comments>http://allaboutlamp.com/2009/09/how-to-prevent-web-server-emails-from-being-marked-as-spam/#comments</comments>
		<pubDate>Tue, 29 Sep 2009 17:36:05 +0000</pubDate>
		<dc:creator>Daniel Lam</dc:creator>
				<category><![CDATA[Email]]></category>
		<category><![CDATA[blacklist]]></category>
		<category><![CDATA[dkim]]></category>
		<category><![CDATA[dns]]></category>
		<category><![CDATA[localhost]]></category>
		<category><![CDATA[mx]]></category>
		<category><![CDATA[reverse dns]]></category>
		<category><![CDATA[spam]]></category>
		<category><![CDATA[spf]]></category>

		<guid isPermaLink="false">http://allaboutlamp.com/?p=20</guid>
		<description><![CDATA[This article describes what you can do, as the system administor / post master of your mail servers, to make sure emails sent from your mail servers go straight to the inboxes of the recipients instead of landing in their spam/junk folder. Because of the bad guys, good guys have to do a lot more to prove their innocence.]]></description>
			<content:encoded><![CDATA[<p><span style="text-decoration: underline;"><strong>Overview</strong></span></p>
<p>Web servers with web applications like forums or blogs often need to send out emails to users. These emails are often legitimate and useful to users, however email providers often incorrectly classify them as spam because of the amount of spam emails found in the internet today.</p>
<p>This article describes what you can do, as the system administor / post master of your mail servers, to make sure emails sent from your mail servers go straight to the inboxes of the recipients instead of landing in their spam/junk folder. Because of the bad guys, good guys have to do a lot more to prove their innocence.</p>
<p><span style="text-decoration: underline;"><strong>Context</strong></span></p>
<p>Solution described in this article has been tested in a Fedora / Postfix setup. Most of the steps are not specific to this setting and can be applied on other environments. Note that these are only possible actions one can *attempt* to prevent emails to be marked as spam. It is ultimately up to the recipient mail servers to decide whether emails are spam or not.</p>
<p>This article assumes reader to have a good understanding of DNS, Unix and web server-related terms and how they work in high level. Most changes described in this article require system-administration / root access to the server.</p>
<p><span style="text-decoration: underline;"><strong>Steps</strong></span></p>
<p><strong>1. Make sure Sender Username and Server Look Legitimate</strong></p>
<p>If you just configured your server to send email, chances are that your out-going emails have words like &#8220;apache&#8221;, &#8220;localhost&#8221;, &#8220;nobody&#8221;, &#8220;localdomain&#8221; all over the place in their mail headers. This is often a sign of improper setup and therefore such mails will be marked as spam by spam filters.</p>
<p>To get rid of them, check the following configurations:</p>
<ul>
<li><code>/etc/hosts</code> This file needs to be set up properly so that the &#8220;hostname&#8221; command returns the public hostname instead of &#8220;localhost&#8221;, and &#8220;hostname -f&#8221; returns the fully-qualified domain name, like &#8220;foo.fooworld.com&#8221;.</li>
<li><code>/etc/httpd/conf/httpd.conf</code> Check the ServerAdmin and SererName of this Apache config file and ensure that it is a valid email address and a fully-qualified domain name.</li>
<li><code>/etc/mail/trusted-users</code> If you need to send emails under a privileged user like apache as some other users such as no-reply@yourdomain.com, modify this file and add the username of the privileged user.</li>
<li><code>/etc/php.ini</code> If you are using php to send emails, you can enforce a different sender identify by adding -f&#8217;sender_address@domain.com&#8217; in the sendmail_path argument.</li>
<li>Use postfix instead of sendmail if you are sending emails from apache and want to ensure that the word &#8220;apache&#8221; is not in the headers of your out-going emails. This is required because in sendmail, even if a &#8220;-f&#8221; option is used to enforce a particular sender identity, the text &#8220;apache@localhost&#8221; will still appear in the first Receive mail header.</li>
<li>The mail header fields &#8220;From&#8221;, &#8220;Reply-To&#8221; and &#8220;Return-Path&#8221; should be the same and be a valid email address, and will not reply with a bounce message if an email is sent to it.</li>
</ul>
<p><strong>2. Setup Reverse DNS</strong></p>
<p>The usual DNS records allow everyone to lookup &#8220;foo.foobar.com&#8221; and find &#8220;123.124.125.126&#8243;. Reverse DNS does the opposite: It allows you to look up the IP address using the domain name. If the domain name and IP address can be used to look up each other, the sender is more likly to be what it claims it is. Therefore this check is employed by spam filter as well.</p>
<p>Note that Reverse DNS setting is not controlled by the domain name server of the domain in question. Using the example above, the DNS server of &#8220;foo.foobar.com&#8221; cannot control its Reverse DNS settings. It is the responsibility of the ISP that maintains 123.124.125.126 to set up its Reverse DNS mapping.</p>
<p>To verify that it has been set up, use &#8220;nslookup &lt;domain name&gt;&#8221; to check for its IP and &#8220;nslookup &lt;ip address&gt;&#8221; to check for its domain name. They should find each other if DNS and Reverse DNS have been set properly.</p>
<p><strong>3. Add SPF Record</strong></p>
<p>SPF record is a TXT record in the domain server, like the other A / CNAME / MX type DNS records, that describes the domain. Spam filter gets the SPF record from DNS server and check if the sender mail server has been allowed or disallowed to send mails.</p>
<p>SPF implementation is free and simple. You can create a SPF record manually if you understand its specification, or you can go to one of the following websites to generate it after answering some questions about your mail server settings.</p>
<p><a href="http://old.openspf.org/wizard.html">http://old.openspf.org/wizard.html</a><br />
<a href="http://www.microsoft.com/mscorp/safety/content/technologies/senderid/wizard/default.aspx">http://www.microsoft.com/mscorp/safety/content/technologies/senderid/wizard/default.aspx</a></p>
<p><strong>4. IP Blacklist Check</strong></p>
<p>Some of the bad guys might have used *your* IP address before to send out spam emails, and now any emails sent from your machine are classified as spam. A website like the one below lets you check if your machine falls into such category, and if it does, lets you request that your IP be taken out from the list. </p>
<p><a href="http://www.mxtoolbox.com/blacklists.aspx">http://www.mxtoolbox.com/blacklists.aspx</a></p>
<p><strong>5. Ensure Mail-Sending Server is listed on MX record</strong></p>
<p>The MX record in the DNS entries tells the whole world which machine should process emails for that domain. If the web server that sends outgoing emails is not listed on one of the MX records, spam filters may think that mails were sent without proper authorisation and therefore should be marked as spam.</p>
<p>As an example, let say you are sending emails from foo.foobar.com. A lookup of MX record of foobar.com shows that the mail server is mail.foobar.com instead. This could be a problem for spam-filter. Configure foo.foobar.com as a proper mail server, point to it using MX record and use it to send and receive emails for foobar.com.</p>
<p><strong>6. Implement DKIM (Domain Keys Identified Mail)</strong></p>
<p>DKIM is similar to SPF. The sender claims that it is from foobar.com and the recipient checks the DNS records of foobar.com to see if the sender is indeed from there. The difference is that, for DKIM, sender has to present a &#8220;signature&#8221; instead of just using its IP to prove its identity.</p>
<p>Refer to this <a href="http://allaboutlamp.com/2009/09/setup-dkim-for-postfix-in-fedora-using-dkim-milter/">article</a> for implementation details of DKIM.</p>
<p>Gmail in particular appear to put emails in inbox only after DKIM has been implemented.</p>
<p><strong>7. Contact Individual Providers</strong></p>
<p>The recipient mail servers may still decide that your emails are spam, even after you have done the whole lot above. </p>
<p>For example, official support from Microsoft stated that &#8220;&#8230; IPs that have little to no history of sending email to Hotmail are more likely to be targeted by SmartScreen&#8230;&#8221;. SmartScreen is one of their spam-filtering tools that filter emails based on machine learning algorithms. With such assumption made by this program, emails from new servers will inevitably go to the junk folder of hotmail addresses.</p>
<p>Advise from official Microsoft Support for this issue is that &#8220;Following all the recommendations (from their postmaster policy guidelines)&#8230; will really make a big difference. Have a nice day!&#8221;. There is not much you can do. However, your out-going emails may become non-junk after a few weeks of SmartScreen learning about your server IP, given that your emails are not labelled as junk by your recipients and emails are sent consistently.</p>
<p>As a last resort, you can try to contact the free email providers directly using the web pages they provide:</p>
<ul>
<li><a href="http://help.yahoo.com/l/us/yahoo/mail/postmaster/bulkv2.html">http://help.yahoo.com/l/us/yahoo/mail/postmaster/bulkv2.html</a> Yahoo Mail support page for marked-as-spam problem
<li><a href="https://support.msn.com/eform.aspx?productKey=edfsmsbl&#038;ct=eformts">https://support.msn.com/eform.aspx?productKey=edfsmsbl&#038;ct=eformts</a> Microsoft support page for marked-as-spam problem
</ul>
<p><span style="text-decoration: underline;"><strong>Errors / Configuration Problems</strong></span></p>
<p><strong>Mail source from Gmail shows &#8220;Received-SPF: neutral&#8221;</strong></p>
<p>This is a sign that your SPF record has not been implemented properly. If it has been done correctly, the header should say &#8220;Received-SPF: pass&#8221; instead. Have you specified the correct IP? Have the DNS records been updated properly?</p>
<p><strong>Mail source from Gmail shows &#8220;dkim=neutral (body hash did not verify)&#8221;</strong></p>
<p>A work-around for this problem is provided in <a href="http://allaboutlamp.com/2009/09/setup-dkim-for-postfix-in-fedora-using-dkim-milter/">http://allaboutlamp.com/2009/09/setup-dkim-for-postfix-in-fedora-using-dkim-milter/</a>.</p>
<p><span style="text-decoration: underline;"><strong>Reference</strong></span></p>
<ul>
<li><a href="http://dnsstuff.com">http://dnsstuff.com</a> A website that generates comprehensive report for your DNS records and tells you how &#8220;healthy&#8221; they are. Make use of the 7-day trial period!</li>
<li><a href="http://www.mxtoolbox.com/blacklists.aspx">http://www.mxtoolbox.com/blacklists.aspx</a> A website to check if the IP address of your mail-sending machine has been blacklisted by spam filters. </li>
<li><a href="http://postmaster.live.com/Troubleshooting.aspx">http://postmaster.live.com/Troubleshooting.aspx</a> Microsoft&#8217;s help for those trying to send emails to hotmail users but marked as spam.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://allaboutlamp.com/2009/09/how-to-prevent-web-server-emails-from-being-marked-as-spam/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>How to Setup DKIM for Postfix in Fedora using dkim-milter</title>
		<link>http://allaboutlamp.com/2009/09/setup-dkim-for-postfix-in-fedora-using-dkim-milter/</link>
		<comments>http://allaboutlamp.com/2009/09/setup-dkim-for-postfix-in-fedora-using-dkim-milter/#comments</comments>
		<pubDate>Mon, 28 Sep 2009 16:02:29 +0000</pubDate>
		<dc:creator>Daniel Lam</dc:creator>
				<category><![CDATA[Email]]></category>
		<category><![CDATA[dkim]]></category>
		<category><![CDATA[dkim-milter]]></category>
		<category><![CDATA[fedora]]></category>
		<category><![CDATA[postfix]]></category>

		<guid isPermaLink="false">http://allaboutlamp.com/?p=1</guid>
		<description><![CDATA[This article describes how to implement DKIM for Postfix in Fedora using the dkim-milter open-source module. This solution has been tested with Fedora 10.]]></description>
			<content:encoded><![CDATA[<p><span style="text-decoration: underline;"><strong>Overview</strong></span></p>
<p>DKIM is a technology that allows mail senders to attach a signature in outgoing mails, so that recipients can check the signatures against DNS records of the sender to see if mail is indeed sent from there.</p>
<p>Because free email providers like gmail make use of DKIM to determine if sender is sending spam, i.e. &#8220;if your domain does not implement DKIM, you are a spammer&#8221;, it is important to implement DKIM for your mail servers to avoid your legitimate out-going emails be classified as spam.</p>
<p><span style="text-decoration: underline;"><strong>Context</strong></span></p>
<p>This article describes how to implement DKIM for Postfix in Fedora using the dkim-milter open-source module. This solution has been tested with Fedora 10.</p>
<p>DKIM allows a domain to be associated with multiple &#8220;signatures&#8221;. Each signature is identified by its &#8220;selector&#8221;. In this example, we are going to create only one signature with its selector named &#8220;default&#8221;.</p>
<p><span style="text-decoration: underline;"><strong>Steps</strong></span></p>
<p><strong>1. Generate a private key</strong></p>
<p><code>openssl genrsa -out default.private 1024</code></p>
<p>A &#8220;default.private&#8221; key file will be generated. It will be moved to a specific location later.</p>
<p><strong>2. Generate a public key for this private key</strong></p>
<p><code>openssl rsa -in default.private -pubout -out default.public -outform PEM</code></p>
<p>A file with filename &#8220;default.public&#8221; will be generated with content like</p>
<p>	<code>-----BEGIN PUBLIC KEY-----<br />
	MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDVqyBW3CvurzAJrWvw/rbiMVL2<br />
	6lytBkhIrgEBWjGWEjjhM6mQpQWLq9VR46xlL4OT6UdVtO8QOMEVI23LN0fwtrPc<br />
	/auwHC2U9joUWTWVjOMZWEywOHwATGevh9TApt2hQJkWjMy/xmCIqBs9VZIweRlf<br />
	VFqc9WEu6VamGe9C3QIDAQAB<br />
	-----END PUBLIC KEY----</code></p>
<p>It will be used to create a DNS TXT record. See next step.</p>
<p><strong>3. Create a DNS record of type TXT</strong></p>
<p>Modify DNS records and add a record of type TXT:</p>
<p>TXT record name<br />
<code>default._domainkey</code></p>
<p>TXT record value<br />
<code>v=DKIM1; g=*; k=rsa; p=<i>&lt;content of default.public&gt;</i></code></p>
<p>Note that the prefix &#8220;&#8212;&#8211;BEGIN PUBLIC KEY&#8212;&#8211;&#8221; and suffix &#8220;&#8212;&#8211;END PUBLIC KEY&#8212;-&#8221; should not be put in the TXT record value.</p>
<p>This DNS record will be retrieved by mail receivers who want to verify emails with DKIM signatures. The record name &#8220;default._domainkey&#8221; tells verifier that the &#8220;selector&#8221; of this signature is  &#8220;default&#8221;, therefore if you are changing selector name to something else, make sure you change all of them consistently.</p>
<p><strong>4. Install dkim-milter in Fedora</strong></p>
<p>Run the following as root to install the dkim-milter pacakge.</p>
<p><code>yum install dkim-milter</code></p>
<p><strong>5. Enable dkim-milter to run on start-up</strong></p>
<p>Make sure dkim-milter service will run on start-up by running this command:</p>
<p><code>chkconfig --level 3 dkim-milter on</code></p>
<p>Note that your server may use a different &#8220;runlevel&#8221;. You can check &#8220;/etc/inittab&#8221; to see which run level you are on.</p>
<p><strong>6. Move private key to appropriate location</strong></p>
<p>As root, copy the private key to the location specified by the &#8220;keylist&#8221; (refer to next step) and make sure it is readable by dkim-milter:</p>
<p><code>mkdir /etc/dkim-milter/<br />
mv default.private /etc/dkim-milter/default<br />
chown dkim-milter.dkim-milter /etc/dkim-milter/default</code></p>
<p>Make sure the filename of private key file matches the &#8220;selector&#8221; name specified in the DNS record.</p>
<p><strong>7. Add an entry to the keylist for dkim-milter to read</strong></p>
<p>Add the following line to /etc/mail/dkim-milter/keys/keylist. Replace &lt;domain.com&gt; with your domain name.</p>
<p><code>*:&lt;domain.com&gt;:/etc/dkim-milter/default</code></p>
<p><strong>8. Configure postfix to use dkim-milter</strong></p>
<p>Add the following lines to /etc/postfix/main.cf to ask postfix to use dkim-milter.</p>
<p><code>smtpd_milters = unix:/var/run/dkim-milter/dkim-milter.sock<br />
non_smtpd_milters = unix:/var/run/dkim-milter/dkim-milter.sock</code></p>
<p><strong>9. Start dkim-milter and restart postfix</strong></p>
<p>Start dkim-milter service and restart postfix using the following commands. Or restart the server.</p>
<p><code>service dkim-milter start<br />
service postfix restart</code></p>
<p><strong>10. Change file permissions of the Mail Filter Socket file</strong></p>
<p>Change file permissions of the &#8220;Mail Filter Socket&#8221; file and its parent directory to allow postfix to write to it:</p>
<p><code>chmod 755 /var/run/dkim-milter<br />
chmod 777 /var/run/dkim-milter/dkim-milter.sock</code></p>
<p>Changing dkim-milter.sock permission unfortunately is required EVERYTIME after dkim-milter servuce is restarted. This is because dkim-milter resets the file to mode 755 that postfix cannot read.</p>
<p>For Fedora, one way to have this done automatically is to add the chmod command in /etc/rc.d/rc.local, so that it will be run on start-up everytime.</p>
<p><span style="text-decoration: underline;"><strong>Errors / Configuration Problems</strong></span></p>
<p><strong>Gmail header says &#8220;dkim=neutral (body hash did not verify)&#8221;</strong></p>
<p>If you are sending emails using mail() function in php, these out-going emails will not be verified by Gmail, for some unknown reason. Opening the mail source in Gmail shows that there is a line &#8220;dkim=neutral (body hash did not verify)&#8221;, hinting that the key in DKIM signature does not match the public key from DNS. Only Gmail knows why. </p>
<p>You may also notice that sending emails directly from the command-line in your server will be DKIM-verified by Gmail, resulting in a &#8220;dkim=pass&#8221; in the mail source headers. Therefore, a work-around for this problem is to modify your php scripts so that it will do a system call to a shell script, which will indirectly send your email out. This way, Gmail will verify your email and put it to the inbox of recipient instead of marking it as spam.</p>
<p><strong>Gmail header says &#8220;dkim=neutral (no key)&#8221; </strong></p>
<p>It means that gmail couldn&#8217;t find a matching key to verify your signature.</p>
<p>So, how does gmail (or any other dkim verifier) find a matching key? It relies on the &#8220;selector name&#8221; from the email header. In the email header there should be something like &#8220;DKIM-Signature: &#8230; s=some_selector_name; t=1254783208;&#8230;&#8221;, here the &#8220;some_selector_name&#8221; is the selector name. Dkim-milter specified that as your selector name as instructed by /etc/mail/dkim-milter/keys/keylist file.</p>
<p>Now if you look at the DNS record for your domain, it needs to have a DKIM public key record (TXT type DNS record) with the name &#8220;some_selector_name._domainkey&#8221; and value being the matching public key. If the name of the record is not &#8220;some_selector_name._domainkey&#8221;, the verifier will not be able to use the public key, because the selector name does not match.</p>
<p>You might have followed an example from internet to set your selector name to &#8220;domain.com_default.key.pem&#8221; and the DNS record name to &#8220;default._domainkey&#8221;, which are not matching each other and therefore getting this no-key message.</p>
<p><span style="text-decoration: underline;"><strong>Reference</strong></span></p>
<ul>
<li><a href="http://www.howtoforge.com/postfix-dkim-with-dkim-milter-centos5.1">http://www.howtoforge.com/postfix-dkim-with-dkim-milter-centos5.1</a> Instructions similar to this article, but for CentOS instead of Fedora. </li>
<li><a href="http://testing.dkim.org/reflector.html">http://testing.dkim.org/reflector.html</a> Free testing to check if your DKIM implementation works.</li>
<li>Config files related to dkim-milter in Fedora:
<p>	Socket file that Postfix connects to<br />
	<code>/var/run/dkim-milter/dkim-milter.sock</code></p>
<p>	Key List file<br />
	<code>/etc/mail/dkim-milter/keys/keylist</code></p>
<p>	Actual private key (can be anywhere as specified by &#8220;Key List&#8221;)<br />
	<code>/etc/dkim-milter/&lt;key filename&gt;</code></p>
<p>	Config file<br />
	<code>/etc/mail/dkim-milter/dkim-filter.conf</code></p>
<p>	Another config file but does not appear to be read by the service<br />
	<code>/etc/sysconfig/dkim-milter</code></p>
<p>	Postfix config that specifies where dkim-milter socket is:<br />
	<code>/etc/postfix/main.cf </code>
</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://allaboutlamp.com/2009/09/setup-dkim-for-postfix-in-fedora-using-dkim-milter/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
	</channel>
</rss>

