<?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 Archives - gj</title>
	<atom:link href="https://blog.gaiterjones.com/tag/relay/feed/" rel="self" type="application/rss+xml" />
	<link>https://blog.gaiterjones.com/tag/relay/</link>
	<description>gaiterjones</description>
	<lastBuildDate>Wed, 19 Apr 2017 07:03:56 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.4.3</generator>
	<item>
		<title>Docker PHP Sendmail Replacement &#8211; SMTP</title>
		<link>https://blog.gaiterjones.com/docker-php-sendmail-replacement-smtp/</link>
					<comments>https://blog.gaiterjones.com/docker-php-sendmail-replacement-smtp/#comments</comments>
		
		<dc:creator><![CDATA[PAJ]]></dc:creator>
		<pubDate>Fri, 03 Mar 2017 14:07:18 +0000</pubDate>
				<category><![CDATA[Docker]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[docker]]></category>
		<category><![CDATA[email]]></category>
		<category><![CDATA[msmtp]]></category>
		<category><![CDATA[php7.php5]]></category>
		<category><![CDATA[relay]]></category>
		<category><![CDATA[sendmail]]></category>
		<guid isPermaLink="false">http://blog.gaiterjones.com/?p=1528</guid>

					<description><![CDATA[If you are relatively new to docker and are migrating php applications to containers you may notice that a lot of docker images recommend using sSMTP as a sendmail replacement...<a class="more-link" href="https://blog.gaiterjones.com/docker-php-sendmail-replacement-smtp/" title="Continue reading">Continue reading</a>]]></description>
										<content:encoded><![CDATA[<p>If you are relatively new to docker and are migrating php applications to containers you may notice that a lot of docker images recommend using sSMTP as a sendmail replacement / smtp transport for php. I wanted my php containers to relay mail to an EXIM4 container but most php base images do not include any type of mail transport system to allow php to relay emails.</p>
<h2>ssmtp cannot rewrite php from header</h2>
<p>Ssmtp does work, but not very well and one major problem I came across was that no matter what configuration settings I tried I could not rewrite the send from SMTP headers in ssmtp I wanted, resulting in all emails being sent from the default <em>root@host</em> address.</p>
<p>The solution is to use msmtp. Msmtp works well with PHP 5.x and 7.x images and allows you to rewrite the from headers. Here is how to build it into your PHP 5.x and 7.x base images.</p>
<h1>FROM php:7-apache</h1>
<p>For <strong>php7</strong> using the official <a href="https://hub.docker.com/_/php/">php-apache docker image</a> you can build msmtp with the following dockerfile commands.</p>
<pre class="brush: plain; title: ; notranslate">
# Install msmtp
RUN set -x \
    &amp;&amp; cd /tmp \
    &amp;&amp; curl -sSL -o msmtp.tar https://sourceforge.net/projects/msmtp/files/latest/download?source=files \
    &amp;&amp; tar -xvf msmtp.tar \
    &amp;&amp; cd msmtp-1.6.6 \
    &amp;&amp; ./configure \
    &amp;&amp; make \
    &amp;&amp; make install \
    &amp;&amp; rm -rf /tmp/msmtp-1.6.6 msmtp.tar \
	&amp;&amp; touch /var/log/msmtp.log \
	&amp;&amp; chmod 777 /var/log/msmtp.log
</pre>
<h1>FROM php:5.6-apache</h1>
<p>For <strong>PHP5.6</strong> you can get mstmp via the apt package manager</p>
<pre class="brush: plain; title: ; notranslate">
RUN set -x \
	&amp;&amp; DEBIAN_FRONTEND=noninteractive \
	&amp;&amp; apt-get update &amp;amp;&amp;amp; apt-get install -y --no-install-recommends msmtp
</pre>
<h1>Configuration</h1>
<p>To configure msmtp create a configuration file and copy that to your container via your dockerfile:</p>
<pre class="brush: plain; title: ; notranslate">COPY ./php/msmtprc /usr/local/etc/msmtprc</pre>
<p>The msmtprc configuration file looks like this</p>
<pre class="brush: plain; title: ; notranslate">
defaults
tls on
tls_certcheck off
tls_starttls on
#tls_trust_file /etc/ssl/certs/ca-certificates.crt

account default
host MAIL_RELAY_1
port 25
logfile /var/log/msmtp.log

auto_from on
maildomain mydomain.com
</pre>
<p>Where host MAIL_RELAY_1 is the name of your mail container or smtp relay. And mydomain.com the mail domain for the container.</p>
<p>To tell php how to send mail include the following in your php.ini file</p>
<pre class="brush: plain; title: ; notranslate">sendmail_path = /usr/local/bin/msmtp -t -i</pre>
<p>&nbsp;</p>
<h1>Testing</h1>
<p>You can either test mail functionality using your php application or via the command line using</p>
<pre class="brush: plain; title: ; notranslate">echo -e &quot;Subject: Test Mail\r\n\r\nThis is a test mail&quot; |msmtp --debug --from=test@email.com -t me@email.com</pre>
<p>If all is configured correctly the email will be relayed successfully.</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.gaiterjones.com/docker-php-sendmail-replacement-smtp/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
	</channel>
</rss>
