<?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>relay &#8211; Blog of Kliment Andreev &#8211; A place so I won&#039;t forget things</title>
	<atom:link href="https://blog.andreev.it/tag/relay/feed/" rel="self" type="application/rss+xml" />
	<link>https://blog.andreev.it</link>
	<description></description>
	<lastBuildDate>Sat, 31 Oct 2020 13:49:56 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	
	<item>
		<title>General: Relay client e-mails using SASL and TLS in postfix</title>
		<link>https://blog.andreev.it/2018/03/124-postfix-relay-client-e-mails-using-sasl-and-tls/</link>
					<comments>https://blog.andreev.it/2018/03/124-postfix-relay-client-e-mails-using-sasl-and-tls/#respond</comments>
		
		<dc:creator><![CDATA[Kliment Andreev]]></dc:creator>
		<pubDate>Sun, 11 Mar 2018 03:20:33 +0000</pubDate>
				<category><![CDATA[CentOS]]></category>
		<category><![CDATA[FreeBSD]]></category>
		<category><![CDATA[OpenBSD]]></category>
		<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[e-mail]]></category>
		<category><![CDATA[postfix]]></category>
		<category><![CDATA[relay]]></category>
		<guid isPermaLink="false">http://blog.iandreev.com/?p=3729</guid>

					<description><![CDATA[I have a bunch of test CentOS/FreeBSD servers and I wanted to get all&#8230;]]></description>
										<content:encoded><![CDATA[<div id="bsf_rt_marker"></div><p>I have a bunch of test CentOS/FreeBSD servers and I wanted to get all the notifications sent to my e-mail instead of logging to each server and check the status of each one of them. Some of my servers are behind my home network where outbound port 25 (SMTP) is blocked by the ISP. So, I decided to use my main postfix server which is already configured to use port 587 for SMTP using TLS. In this post, I&#8217;ll explain how I configured my test servers to relay e-mails.<br />
Use the following links to see how I configured the postfix main server for <a href="https://blog.andreev.it/?p=1975" rel="noopener noreferrer" target="_blank">CentOS </a>and <a href="https://blog.andreev.it/?p=1604" rel="noopener noreferrer" target="_blank">FreeBSD</a>. </p>
<h1>CentOS 7</h1>
<p>There are some prerequisites for CentOS 7. It comes with postfix installed and it has built-in Cyrus SASL already, but we need another Cyrus SASL package for login support. In addition, CentOS doesn&#8217;t come up with the mail command, so we have to install that as well.</p>
<h2>Prerequisites</h2>
<p>Install Cyrus SASL package and the mail client.</p>
<pre class="brush: bash; title: ; notranslate">
yum install cyrus-sasl-plain mailx
</pre>
<h2>postfix main config file</h2>
<p>Edit <strong>/etc/postfix/main.cf</strong> and add these lines at the end.</p>
<pre class="brush: bash; title: ; notranslate">
relayhost = &#x5B;server.domain.com]:587
smtp_sasl_auth_enable = yes
smtp_sasl_security_options = noanonymous
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_use_tls = yes
smtp_tls_CAfile = /etc/ssl/certs/server.domain.com.crt
</pre>
<p>The first line is your main postfix server that will receive the e-mail from the client servers, the 4th line is the file where you are going to store the username and password for the user that&#8217;s able to login to the main postfix server and the 6th line is the certificate of the main postfix server. </p>
<h2>SASL Authentication</h2>
<p>Edit <strong>/etc/postfix/sasl_passwd</strong> and add this line.</p>
<pre class="brush: bash; title: ; notranslate">
&#x5B;server.domain.com]:587 mail@domain.com:YourPassword
</pre>
<p>You have to specify your main postfix server, the username and the password for a valid user that&#8217;s able to login to that server and receive e-mails. Once completed, execute postmap.</p>
<pre class="brush: bash; title: ; notranslate">
postmap /etc/postfix/sasl_passwd
</pre>
<h2>e-mails to relay</h2>
<p>I wanted to send all of my root e-mails to my main server, so what you have to do is edit <strong>/etc/aliases</strong> and scroll all the way down at the bottom. Un-comment the root line and specify where do you want your root emails to be forwarded.</p>
<pre class="brush: bash; title: ; notranslate">
root: mail@domain.com
</pre>
<p>If you have some cron jobs that run under some other username, specify them in this file, e.g. someuser: some-email@email.com.<br />
After you are done, type newaliases.</p>
<pre class="brush: bash; title: ; notranslate">
newaliases
</pre>
<h2>Public certificate</h2>
<p>You will also need the public certificate of your e-mail server. Get the certificate in a PEM format and paste it into a new file <strong>/etc/ssl/certs/server.domain.com.crt</strong>. Or, in my case, I have a wildcard certificate for my domain, so I can get it using this command.</p>
<pre class="brush: bash; title: ; notranslate">
openssl s_client -connect server.domain.com:443 &lt; /dev/null | \
sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' &gt; /etc/ssl/certs/server.domain.com.crt
</pre>
<h2>Final step</h2>
<p>Restart the postfix server on the client server, send a test e-mail and check the result.</p>
<pre class="brush: bash; title: ; notranslate">
systemctl restart postfix
echo &quot;This is a test.&quot; | mail -s &quot;Test e-mail&quot; root
tail /var/log/maillog
</pre>
<h1>FreeBSD 11</h1>
<p>Unlike CentOS, FreeBSD doesn&#8217;t come up with postfix, instead it uses sendmail. So, we have to remove sendmail, install postfix and follow similar config as with CentOS.</p>
<h2>Prerequisites</h2>
<p>We have to install postfix from the ports because it doesn&#8217;t come up with Cyrus SASL. It comes with dovecot SASL, but I am not sure if it works in a client config. On the other hand, FreeBSD comes with mail installed. Install the postfix port, not the package. </p>
<pre class="brush: bash; title: ; notranslate">
cd /usr/ports
</pre>
<p>If you get an error that there is no such file or directory, get the ports tree. If you can cd to that folder, skip the step below to install the ports tree.</p>
<pre class="brush: bash; title: ; notranslate">
portsnap fetch
portsnap extract
</pre>
<p>Install postfix.</p>
<pre class="brush: bash; title: ; notranslate">
cd /usr/ports/mail/postfix
make all install clear
</pre>
<p>When this dialog box pops-up, select <strong>BDB </strong>and <strong>SASL </strong>as highlighted.<br />
<a href="https://blog.andreev.it/wp-content/uploads/2018/03/P101-01.png"><img fetchpriority="high" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2018/03/P101-01.png" alt="" width="537" height="324" class="aligncenter size-full wp-image-8191" /></a><br />
Execute these lines so you replace sendmail with postfix.</p>
<pre class="brush: bash; title: ; notranslate">
sysrc postfix_enable=&quot;YES&quot;
sysrc sendmail_enable=&quot;NONE&quot;
mv /usr/local/etc/mail/mailer.conf /usr/local/etc/mail/mailer.conf.old
install -m 0644 /usr/local/share/postfix/mailer.conf.postfix /usr/local/etc/mail/mailer.conf
</pre>
<p>Add the following lines to <strong>/etc/defaults/periodic.conf</strong></p>
<pre class="brush: bash; title: ; notranslate">
daily_clean_hoststat_enable=&quot;NO&quot;
daily_status_mail_rejects_enable=&quot;NO&quot;
daily_status_include_submit_mailq=&quot;NO&quot;
daily_submit_queuerun=&quot;NO&quot;
</pre>
<p>Make sure Cyrus SASL is installed.</p>
<pre class="brush: bash; title: ; notranslate">
postconf -a
</pre>
<p>You should see cyrus and dovecot there.</p>
<h2>postfix main config file</h2>
<p>Edit <strong>/usr/local/etc/postfix/main.cf</strong> and add these lines at the end.</p>
<pre class="brush: bash; title: ; notranslate">
relayhost = &#x5B;server.domain.com]:587
smtp_sasl_auth_enable = yes
smtp_sasl_security_options = noanonymous
smtp_sasl_password_maps = hash:/usr/local/etc/postfix/sasl_passwd
smtp_use_tls = yes
smtp_tls_CAfile = /usr/local/etc/ssl/server.domain.com.crt
</pre>
<p>The first line is your main postfix server that will receive the e-mail from the client servers, the 4th line is the file where you are going to store the username and password for the user that’s able to login to the main postfix server and the 6th line is the certificate of the main postfix server.</p>
<h2>SASL Authentication</h2>
<p>Edit <strong>/usr/local/etc/postfix/sasl_passwd</strong> and add this line.</p>
<pre class="brush: bash; title: ; notranslate">
&#x5B;server.domain.com]:587 mail@domain.com:YourPassword
</pre>
<p>You have to specify your main postfix server, the username and the password for a valid user that’s able to login to that server and receive e-mails. Once completed, execute postmap.</p>
<pre class="brush: bash; title: ; notranslate">
postmap /usr/local/etc/postfix/sasl_passwd
</pre>
<h2>e-mails to relay</h2>
<p>I wanted to send all of my root e-mails to my main server, so what you have to do is edit <strong>/etc/aliases</strong> and scroll a little bit way down. Un-comment the root line and specify where do you want your root emails to be forwarded.</p>
<pre class="brush: bash; title: ; notranslate">
root: mail@domain.com
</pre>
<p>If you have some cron jobs that run under some other username, specify them in this file, e.g. <strong>someuser: some-email@email.com.</strong><br />
After you are done, type <strong>newaliases</strong>.</p>
<pre class="brush: bash; title: ; notranslate">
newaliases
</pre>
<h2>Public certificate</h2>
<p>You will also need the public certificate of your e-mail server. Get the certificate in a PEM format and paste it into a new file <strong>/usr/local/etc/ssl/server.domain.com.crt</strong>. Or, in my case, I have a wildcard certificate for my domain, so I can get it using this command.</p>
<pre class="brush: bash; title: ; notranslate">
openssl s_client -connect server.domain.com:443 &lt; /dev/null | \
sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' &gt; /usr/local/etc/ssl/server.domain.com.crt
</pre>
<h2>Final step</h2>
<p>Restart the postfix server on the client server, send a test e-mail and check the result.</p>
<pre class="brush: bash; title: ; notranslate">
service postfix restart
echo &quot;This is a test.&quot; | mail -s &quot;Test e-mail&quot; root
tail /var/log/maillog
</pre>
<p>You will notice that the e-mails that come from FreeBSD are always sent by Charlie Root. If you have multiple FreeBSD boxes, the e-mails from various FreeBSD servers will come as Charlie Root which might be a bit confusing. So do a <strong>chpass </strong>and change the line <strong>Full Name</strong>, so instead of <strong>Full Name: Charlie &#038;</strong>, do something like <strong>Full Name: servername Charlie &#038;</strong>.</p>
<pre class="brush: bash; title: ; notranslate">
chpass
</pre>
<p><a href="https://blog.andreev.it/wp-content/uploads/2018/03/P101-02.png"><img decoding="async" src="https://blog.andreev.it/wp-content/uploads/2018/03/P101-02.png" alt="" width="565" height="253" class="aligncenter size-full wp-image-8192" /></a><br />
Do <strong><ESC>:wq</strong> if your default editor is vi to save the changes.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.andreev.it/2018/03/124-postfix-relay-client-e-mails-using-sasl-and-tls/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>General: postfix relay for another domain</title>
		<link>https://blog.andreev.it/2012/01/postfix-relay-for-other-domain/</link>
					<comments>https://blog.andreev.it/2012/01/postfix-relay-for-other-domain/#respond</comments>
		
		<dc:creator><![CDATA[Kliment Andreev]]></dc:creator>
		<pubDate>Wed, 18 Jan 2012 19:30:36 +0000</pubDate>
				<category><![CDATA[AIX]]></category>
		<category><![CDATA[CentOS]]></category>
		<category><![CDATA[FreeBSD]]></category>
		<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[postfix]]></category>
		<category><![CDATA[relay]]></category>
		<guid isPermaLink="false">http://blog.iandreev.com/?p=235</guid>

					<description><![CDATA[I have two registered domains both pointing to my FreeBSD external IP. The first&#8230;]]></description>
										<content:encoded><![CDATA[<div id="bsf_rt_marker"></div><p>I have two registered domains both pointing to my FreeBSD external IP. The first one is chombe.org and I receive these e-mails on my FreeBSD using postfix. The second domain is klimentandreev.com and I use Exchange 2003 to receive e-mails for this domain. Since Exchange is on the internal network, I have to configure postfix to relay all e-mails for klimentandreev.com to the Exchange box.</p>
<p>First, I made sure that I can ping klimentandreev.com from FreeBSD box and that it will resolve to my internal IP. Next, I edited <strong>main.cf</strong> and changed <strong>relay_domains</strong> to be like this.</p>
<pre class="brush: bash; title: ; notranslate">
relay_domains = $mydestionation, /usr/local/etc/postfix/relay-domains 
</pre>
<p>Then, I created that file and added the following lines.</p>
<pre class="brush: bash; title: ; notranslate">
# Relay domains
klimentandreev.com
other-domain-that-i-will-probably-buy.com
</pre>
<p>After that, I reloaded postfix with <strong>/usr/local/etc/rc.d/postfix reload</strong> and I verified that postfix is relaying OK. I didn’t have to configure anything on the Exchange box.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.andreev.it/2012/01/postfix-relay-for-other-domain/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
