<?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>Zulius &#187; postfix</title>
	<atom:link href="http://www.zulius.com/tag/postfix/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.zulius.com</link>
	<description>Advanced Application Development</description>
	<lastBuildDate>Tue, 07 Feb 2012 16:09:39 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Setup Postfix with a remote SMTP relay host</title>
		<link>http://www.zulius.com/how-to/set-up-postfix-with-a-remote-smtp-relay-host/</link>
		<comments>http://www.zulius.com/how-to/set-up-postfix-with-a-remote-smtp-relay-host/#comments</comments>
		<pubDate>Thu, 12 Nov 2009 05:59:24 +0000</pubDate>
		<dc:creator>Tim White</dc:creator>
				<category><![CDATA[how-to]]></category>
		<category><![CDATA[postfix]]></category>
		<category><![CDATA[smtp]]></category>

		<guid isPermaLink="false">http://www.zulius.com/wordpress/?p=3</guid>
		<description><![CDATA[Platforms: any Linux distro What You'll Need: Postfix 2.2+ cyrus-sasl 2.1.19+3rd party email account A typical email scenario: you're a developer, and you've got a development Linux box at home. You need to be able to send emails from your code or cron jobs, but you're too lazy to set up a full fledged email [...]]]></description>
			<content:encoded><![CDATA[<div style="float:right">
<div class="wp-caption alignleft" style="width: 159px"><img alt="Postfix config" src="/img/blog/postfixTitleImage.jpg" title="Postfix config" width="149" height="110" /><p class="wp-caption-text">Postfix config</p></div></p>
<div class="clear"></div>
</div>
<p><strong>Platforms: </strong><br />any Linux distro</p>
<p><strong>What You'll Need:</strong><br /> <a href="http://www.postfix.org">Postfix 2.2+</a><br /> <a href="http://freshmeat.net/projects/cyrussasl/">cyrus-sasl 2.1.19+</a><br />3rd party email account
</p>
<p>A typical email scenario: you're a developer, and you've got a development Linux box at home.  You need to be able to send emails from your code or cron jobs, but you're too lazy to set up a full fledged email server on your LAN.  Or you just want to use an email account provided by Google Apps, Yahoo, or your ISP.</p>
<p>Enter the Postfix.</p>
<p>Most Linux distros come with <a href="http://www.sendmail.org/">Sendmail</a> already installed, and is usually the default mail client used by the running services.  However, Postfix <a href="http://www.akadia.com/services/postfix_mta.html" target="_self">beats the crap out of Sendmail</a> and is a complete, seamless replacement.  Here's how I got it going on my CentOS box.</p>
<h2>Install</h2>
<p>Install Postfix and cyrus-sasl with your application manager of choice.  If you're compiling from source, be sure to make Postfix with the -DUSE_SASL_AUTH flag for SASL support and -DUSE_TLS for TLS support.</p>
<pre class="brush: plain;">$ yum install postfix cyrus-sasl</pre>
<p>Stop the sendmail service</p>
<pre class="brush: plain;">$ /etc/init.d/sendmail stop</pre>
<p>Remove sendmail from the startup runlevels</p>
<pre class="brush: plain;">$ chkconfig --del sendmail</pre>
<h2>Typical Setup</h2>
<p>Edit /etc/postfix/main.cf</p>
<pre class="brush: plain;"># Set this to your server's fully qualified domain name.
# If you don't have a internet domain name,
# use the default or your email addy's domain - it'll keep
# postfix from generating warnings all the time in the logs
mydomain = local.domain
myhostname = host.local.domain

# Set this to your email provider's smtp server.
# A lot of ISP's (ie. Cox) block the default port 25
# for home users to prevent spamming.  So we'll use port 80
relayhost = yourisp.smtp.servername:80

smtpd_sasl_auth_enable = yes
smtpd_sasl_path = smtpd
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_type = cyrus
smtp_sasl_auth_enable = yes

# optional: necessary if email provider uses load balancing and
# forwards emails to another smtp server
# for delivery (ie: smtp.yahoo.com --&gt; smtp.phx.1.yahoo.com)
smtp_cname_overrides_servername = no

# optional: necessary if email provider
# requires passwords sent in clear text
smtp_sasl_security_options = noanonymous</pre>
<p>There's roughly a 99.9% chance that your email provider's SMTP server requires authentication.  We need to set that up with the username and password given by your email provider.</p>
<p>Add the following line to /etc/postfix/sasl_passwd</p>
<pre class="brush: plain;">
yourisp.smtp.servername:80 username:password</pre>
<p>The above server hostname and port must exactly match the value for "relayhost" in /etc/postfix/main.cf.</p>
<p>Generate a postfix lookup table from the previous file</p>
<pre class="brush: plain;">$ postmap hash:/etc/postfix/sasl_passwd</pre>
<p>Test the lookup table, if all is good then the following will return the specified username:password</p>
<pre class="brush: plain;">$ postmap -q yourisp.smtp.servername:80 /etc/postfix/sasl_passwd</pre>
<p>Make sure the sasl_passwd and sasl_passwd.db files are readable/writable only by root</p>
<pre class="brush: plain;">$ chmod 600 /etc/postfix/sasl_passwd
$ chmod 600 /etc/postfix/sasl_passwd.db
</pre>
<p>Add postfix to be started at boot</p>
<pre class="brush: plain;">$ chkconfig --add postfix</pre>
<p>Fire up Postfix</p>
<pre class="brush: plain;">$ /etc/init.d/postfix start</pre>
<p>Test it out using sendmail alias from the command prompt</p>
<pre class="brush: plain;">$ sendmail email@example.com
Postfix is good to go.
.</pre>
<h2>Gmail Setup</h2>
<p>
If you're attempting to relay mail using Gmail, then it will be necessary to use TLS with Postfix.  You'll have to point Postfix at your server's trusted CA root certificate bundle, but luckily "<a href="http://www.felipe-alfaro.org/blog/2009/05/10/have-postfix-relay-e-mail-to-gmail/">...client-side certificates are not required when relaying mail to GMail</a>".
</p>
<p>First, double-check that Postfix was configured with SSL support (ie. ldd should return at least one line starting with libssl):</p>
<pre class="brush: plain;">$ whereis -b postfix
postfix: /usr/sbin/postfix /etc/postfix /usr/libexec/postfix
$ ldd /usr/sbin/postfix
...
libssl.so.6 =&gt; /lib/libssl.so.6 (0x00111000)
...
</pre>
<p>Now we need to find your server's CA root certificate bundle, which is typically distributed with openssl.  The bundle file is used by Postfix to verify Gmail's SSL certificate (signed by Thawte). On my CentOS server, this file was located at /etc/pki/tls/certs/ca-bundle.crt, but may be in a different location on your box (ie. /etc/ssl/certs).</p>
<pre class="brush: plain;">$ locate ca-bundle.crt
/etc/pki/tls/certs/ca-bundle.crt
</pre>
<p>Edit /etc/postfix/main.cf with the following values:</p>
<pre class="brush: plain;">
relayhost = smtp.gmail.com:587

# your FQDN, or default value below
mydomain = local.domain

# your local machine name, or default value below
myhostname = host.local.domain
myorigin = $myhostname

# SASL
smtpd_sasl_path = smtpd
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_type = cyrus
smtp_sasl_auth_enable = yes
smtp_sasl_security_options = noanonymous

# TLS
smtp_sasl_tls_security_options = noanonymous
smtp_use_tls  = yes
smtp_tls_CAfile = /path/to/your/ca-bundle.crt
smtp_sasl_tls_security_options = noanonymous
</pre>
<p>If you haven't already, add the following to /etc/postfix/sasl_passwd</p>
<pre class="brush: plain;">
smtp.gmail.com:587 username:password</pre>
<p>Generate a postfix lookup table from the previous file</p>
<pre class="brush: plain;">$ postmap hash:/etc/postfix/sasl_passwd</pre>
<p>Make sure the sasl_passwd and sasl_passwd.db files are readable/writable only by root</p>
<pre class="brush: plain;">$ chmod 600 /etc/postfix/sasl_passwd
$ chmod 600 /etc/postfix/sasl_passwd.db
</pre>
<p>Restart postfix and send a test email</p>
<pre class="brush: plain;">$ postfix reload
$ sendmail email@example.com
Test relay thru Gmail
.</pre>
<h2>Troubleshooting</h2>
<p>Monitor postfix mail log in a separate session with the following command</p>
<pre class="brush: plain;">$ tail -f /var/log/maillog</pre>
<p>If the log is displaying the following error</p>
<pre class="brush: plain; toolbar: false;">(Authentication failed: cannot SASL authenticate to server ...: no mechanism available)</pre>
<p>then set this variable in /etc/postfix/main.cf</p>
<pre class="brush: plain;">smtp_sasl_security_options = noanonymous</pre>
<p>If the log is displaying this error</p>
<pre class="brush: plain; toolbar: false;">553 Sorry, that domain isn't in my list of allowed rcpthosts. (in reply to RCPT TO command)</pre>
<p>check your username and password in /etc/postfix/sasl_passwd.  Your user name is usually your full email address.  If you have to fix it, don't forget to use postmap to generate a new lookup table.</p>
<img src="http://www.zulius.com/blog/?ak_action=api_record_view&id=3&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.zulius.com/how-to/set-up-postfix-with-a-remote-smtp-relay-host/feed/</wfw:commentRss>
		<slash:comments>43</slash:comments>
		</item>
	</channel>
</rss>

