<?xml version="1.0" encoding="utf-8" standalone="yes"?><feed xmlns="http://www.w3.org/2005/Atom" xml:base="https://foundata.com/" xml:lang="en"><title>Proxmox on foundata</title><id>https://foundata.com/en/tags/proxmox/feed-atom.xml</id><link rel="self" type="application/atom+xml" hreflang="en" href="https://foundata.com/en/tags/proxmox/feed-atom.xml" title="atom"/><link rel="alternate" type="text/html" hreflang="en" href="https://foundata.com/en/tags/proxmox/" title="html"/><link rel="alternate" type="application/rss+xml" hreflang="en" href="https://foundata.com/en/tags/proxmox/feed-rss.xml" title="rss"/><link rel="alternate" type="application/atom+xml" hreflang="de" href="https://foundata.com/de/tags/proxmox/feed-atom.xml" title="atom, Deutsch"/><link rel="alternate" type="text/html" hreflang="de" href="https://foundata.com/de/tags/proxmox/feed-atom.xml" title="html, Deutsch"/><link rel="alternate" type="application/rss+xml" hreflang="de" href="https://foundata.com/de/tags/proxmox/feed-atom.xml" title="rss, Deutsch"/><updated>2023-09-01T18:09:00Z</updated><author><name>foundata GmbH</name><email>webmaster@foundata.com</email><uri>https://foundata.com/</uri></author><rights>© 2023-2026, foundata GmbH (https://foundata.com)</rights><icon>https://foundata.com/images/feed-icon.67ff83c698af1511552374e80cf5f6ff26d497ef21f04186cf058859d535ca75.svg</icon><logo>https://foundata.com/images/feed-logo.9138f24a120dabc7e3d34003662131cc9c7f2ff153ec39d2f6dea3a48c35b4bf.svg</logo><entry><title type="html">Proxmox VE: Setting up email sending (mail relay / smart host)</title><id>tag:foundata.com,2023-09-01:/en/blog/2023/proxmox-pve-email-relay-smart-host/</id><published>2023-09-01T18:09:00Z</published><updated>2023-09-01T18:09:00Z</updated><link href="https://foundata.com/en/blog/2023/proxmox-pve-email-relay-smart-host/?utm_source=feed-atom" rel="alternate" type="text/html"/><link href="https://foundata.com/de/blog/2023/proxmox-pve-email-relay-smart-host/?utm_source=feed-atom" rel="alternate" type="text/html" hreflang="de"/><author><name>Andreas Haerter</name><uri>https://andreashaerter.com/</uri></author><author><name>Frederik Meissner</name></author><summary type="html">Instructions for setting up email sending via smart host on Proxmox Virtual Environment (PVE).</summary><content type="html" xml:base="https://foundata.com/"><![CDATA[<p><a href="https://foundata.com/en/virtualization/">Proxmox Virtual Environment (PVE) servers</a> are usually important systems as they are hosts for virtual machines and containers. Nevertheless, there are often installations that are not able to send emails to inform about updates, backup results or the like. On this page, we briefly explain how to configure PVE to allow sending emails via external email server (<a href="https://en.wikipedia.org/wiki/Smart_host" target="_blank" rel="noreferrer noopener">relay / smart host</a>).</p>
<h2 id="postfix" class="scroll-mt-20 md:scroll-mt-24 wrap-break-word group/heading "><a href="#postfix" class="group-hover/heading:after:content-['#'] group-hover/heading:after:ml-1.5 group-hover/heading:after:text-content-400" id="postfix">Postfix</a></h2><p>Postfix is a Mail Transfer Agent (MTA) and should already be installed on the system. If not, you can simply fix this:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">apt-get install postfix
</span></span><span class="line"><span class="cl">systemctl <span class="nb">enable</span> postfix
</span></span></code></pre></div><h3 id="basic-configuration" class="scroll-mt-20 md:scroll-mt-24 wrap-break-word group/heading "><a href="#basic-configuration" class="group-hover/heading:after:content-['#'] group-hover/heading:after:ml-1.5 group-hover/heading:after:text-content-400" id="basic-configuration">Basic configuration</a></h3><p>With a suitable configuration, Postfix ensures that the emails are accepted by the local system and forwarded to an external mail system via <a href="https://en.wikipedia.org/wiki/Simple_Mail_Transfer_Protocol" target="_blank" rel="noreferrer noopener">SMTP</a>.</p>
<p>The main configuration file is <code>/etc/postfix/main.cf</code>. First you should make sure that the relay is only usable via <code>localhost</code> by Proxmox or other system services and not by third parties via the network:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-ini" data-lang="ini"><span class="line"><span class="cl"><span class="na">myhostname</span> <span class="o">=</span> <span class="s">pve.example.com</span>
</span></span><span class="line"><span class="cl"><span class="na">mydomain</span> <span class="o">=</span> <span class="s">example.com</span>
</span></span><span class="line"><span class="cl"><span class="na">mydestination</span> <span class="o">=</span> <span class="s">$myhostname, localhost.$mydomain, localhost</span>
</span></span><span class="line"><span class="cl"><span class="na">mynetworks</span> <span class="o">=</span> <span class="s">127.0.0.0/8</span>
</span></span><span class="line"><span class="cl"><span class="na">inet_interfaces</span> <span class="o">=</span> <span class="s">loopback-only</span>
</span></span></code></pre></div><p>Replace <code>pve.example.com</code> with the system&rsquo;s FQDN<sup id="fnref:1"><a href="#fn:1" class="footnote-ref" role="doc-noteref">1</a></sup> and <code>example.com</code> with the email sender domain. By default, <code>mydestination</code>, <code>mynetworks</code> and <code>inet_interfaces</code> should already have the correct values.</p>
<h3 id="relay--smart-host" class="scroll-mt-20 md:scroll-mt-24 wrap-break-word group/heading "><a href="#relay--smart-host" class="group-hover/heading:after:content-['#'] group-hover/heading:after:ml-1.5 group-hover/heading:after:text-content-400" id="relay--smart-host">Relay / smart host</a></h3><p>Another package is needed for authentication on the external mail server which is used for the actual sending:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">apt-get install libsasl2-modules
</span></span></code></pre></div><p>The relay settings are also set in <code>/etc/postfix/main.cf</code>. The setting <code>relayhost =</code> already exists in the file by default (without value) and can be adapted. Any other options that didn&rsquo;t already exist in the configuration were simply added at the end of the file:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-ini" data-lang="ini"><span class="line"><span class="cl"><span class="na">relayhost</span> <span class="o">=</span> <span class="s">[your-mailserver-on-the-internet.example.com]:587</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="c1"># [...]</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="c1"># enable SASL authentication?</span>
</span></span><span class="line"><span class="cl"><span class="na">smtp_sasl_auth_enable</span> <span class="o">=</span> <span class="s">yes</span>
</span></span><span class="line"><span class="cl"><span class="c1"># disallow methods that allow anonymous authentication.</span>
</span></span><span class="line"><span class="cl"><span class="na">smtp_sasl_security_options</span> <span class="o">=</span> <span class="s">noanonymous</span>
</span></span><span class="line"><span class="cl"><span class="na">smtp_sasl_tls_security_options</span> <span class="o">=</span> <span class="s">noanonymous</span>
</span></span><span class="line"><span class="cl"><span class="c1"># where to find sasl_passwd</span>
</span></span><span class="line"><span class="cl"><span class="na">smtp_sasl_password_maps</span> <span class="o">=</span> <span class="s">hash:/etc/postfix/sasl_passwd</span>
</span></span><span class="line"><span class="cl"><span class="c1"># TLS transport encryption; may = STARTTLS; encrypt = Enforce TLS</span>
</span></span><span class="line"><span class="cl"><span class="na">smtp_tls_security_level</span> <span class="o">=</span> <span class="s">may</span>
</span></span><span class="line"><span class="cl"><span class="c1"># where to find CA certificates (smtp_tls_CApath should have same value if existing)</span>
</span></span><span class="line"><span class="cl"><span class="na">smtp_tls_CAfile</span> <span class="o">=</span> <span class="s">/etc/ssl/certs/ca-certificates.crt</span>
</span></span><span class="line"><span class="cl"><span class="c1"># maximum amount of memory in bytes for storing a message header (default: 102400)</span>
</span></span><span class="line"><span class="cl"><span class="na">header_size_limit</span> <span class="o">=</span> <span class="s">4096000</span>
</span></span></code></pre></div><p><code>[your-mailserver-on-the-internet.example.com]:587</code> has to be replaced with your own mail server and a suitable port (usually <code>587</code> or <code>25</code>). If this server requires a user name and password (→ <code>smtp_sasl_auth_enable = yes</code>), the access data must be saved in the file <code>/etc/postfix/sasl_passwd</code> in the following form:</p>
<pre tabindex="0"><code>your-mailserver-on-the-internet.example.com   username:password
</code></pre><p><em>After every change</em> to <code>/etc/postfix/sasl_passwd</code>, the associated postfix mapping must be updated:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">postmap /etc/postfix/sasl_passwd
</span></span><span class="line"><span class="cl">systemctl restart postfix.service
</span></span></code></pre></div><p>The file should only be readable by <code>root</code> as it contains credentials:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">chown <span class="s2">&#34;root:root&#34;</span> <span class="s2">&#34;/etc/postfix/sasl_passwd&#34;</span>
</span></span><span class="line"><span class="cl">chmod <span class="m">0600</span> <span class="s2">&#34;/etc/postfix/sasl_passwd&#34;</span>
</span></span></code></pre></div><h3 id="enforce-correct-sender-address" class="scroll-mt-20 md:scroll-mt-24 wrap-break-word group/heading "><a href="#enforce-correct-sender-address" class="group-hover/heading:after:content-['#'] group-hover/heading:after:ml-1.5 group-hover/heading:after:text-content-400" id="enforce-correct-sender-address">Enforce correct sender address</a></h3><p>A simple configuration can be used to ensure that the sender information for e-mails to the relay is set to <code>do-not-reply@example.com</code> (you <strong>must replace <code>@example.com</code> with the valid sender domain</strong> in the following / has to be set to the value used for <code>mydomain =</code>).</p>
<p>In <code>/etc/postfix/main.cf</code>:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-ini" data-lang="ini"><span class="line"><span class="cl"><span class="na">sender_canonical_classes</span> <span class="o">=</span> <span class="s">envelope_sender, header_sender</span>
</span></span><span class="line"><span class="cl"><span class="na">sender_canonical_maps</span> <span class="o">=</span> <span class="s">regexp:/etc/postfix/sender_canonical</span>
</span></span><span class="line"><span class="cl"><span class="na">smtp_header_checks</span> <span class="o">=</span> <span class="s">regexp:/etc/postfix/header_check</span>
</span></span></code></pre></div><p>Content of <code>/etc/postfix/sender_canonical</code>:</p>
<pre tabindex="0"><code>/.+/    do-not-reply@example.com
</code></pre><p><em>After every change</em> to <code>/etc/postfix/sender_canonical</code>, the associated postfix mapping must be updated:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">postmap /etc/postfix/sender_canonical
</span></span></code></pre></div><p>Content of <code>/etc/postfix/header_check</code>:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-ini" data-lang="ini"><span class="line"><span class="cl"><span class="na">/From:.*/ REPLACE From: pve.example.com (Proxmox, PVE) &lt;do-not-reply@example.com&gt;</span>
</span></span></code></pre></div><p>These files should only be readable by <code>root</code>, too:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">chown <span class="s2">&#34;root:root&#34;</span> <span class="s2">&#34;/etc/postfix/sender_canonical&#34;</span>
</span></span><span class="line"><span class="cl">chmod <span class="m">0600</span> <span class="s2">&#34;/etc/postfix/sender_canonical&#34;</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">chown <span class="s2">&#34;root:root&#34;</span> <span class="s2">&#34;/etc/postfix/header_check&#34;</span>
</span></span><span class="line"><span class="cl">chmod <span class="m">0600</span> <span class="s2">&#34;/etc/postfix/header_check&#34;</span>
</span></span></code></pre></div><h3 id="root-alias" class="scroll-mt-20 md:scroll-mt-24 wrap-break-word group/heading "><a href="#root-alias" class="group-hover/heading:after:content-['#'] group-hover/heading:after:ml-1.5 group-hover/heading:after:text-content-400" id="root-alias"><code>root</code> alias</a></h3><p>Mails for the <code>root</code> user of the system can also be easily forwarded to an admin email address. To do this, add a line to the <code>/etc/aliases</code> file (adjust <code>admin@example.net</code> to a suitable target address):</p>
<pre tabindex="0"><code>[...]
root: admin@example.net
</code></pre><p><em>After every change</em> to <code>/etc/aliases</code>, the postfix alias database needs to be updated:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">postalias /etc/aliases
</span></span></code></pre></div><p>The appropriate setting is already existing in <code>/etc/postfix/main.cf</code> by default, but you can check this again:</p>
<pre tabindex="0"><code>alias_maps = hash:/etc/aliases
</code></pre><h2 id="sender-and-user-addresses-in-pve" class="scroll-mt-20 md:scroll-mt-24 wrap-break-word group/heading "><a href="#sender-and-user-addresses-in-pve" class="group-hover/heading:after:content-['#'] group-hover/heading:after:ml-1.5 group-hover/heading:after:text-content-400" id="sender-and-user-addresses-in-pve">Sender and user addresses in PVE</a></h2><p>If you have configured Postfix as described above, the sender address will be adjusted or overwritten by the settings in <code>/etc/postfix/sender_canonical</code> and <code>/etc/postfix/header_check</code>. Nevertheless, for the sake of form, you can still set the sender address to the correct value in the web UI at &ldquo;Datacenter → Options → Email from address&rdquo;.</p>
<p>In addition, the e-mail addresses of the PVE user accounts can be specified at &ldquo;Datacenter → Permissions → Users&rdquo;.</p>
<h2 id="test-and-debugging" class="scroll-mt-20 md:scroll-mt-24 wrap-break-word group/heading "><a href="#test-and-debugging" class="group-hover/heading:after:content-['#'] group-hover/heading:after:ml-1.5 group-hover/heading:after:text-content-400" id="test-and-debugging">Test and debugging</a></h2><div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">systemctl restart postfix.service
</span></span><span class="line"><span class="cl">systemctl status postfix.service
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="c1"># send test mail to admin@example.com</span>
</span></span><span class="line"><span class="cl"><span class="nb">echo</span> <span class="s2">&#34;This is the message&#34;</span> <span class="p">|</span> mail -s <span class="s2">&#34;Hello World from </span><span class="k">$(</span>hostname<span class="k">)</span><span class="s2">&#34;</span> <span class="s2">&#34;admin@example.com&#34;</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="c1"># log</span>
</span></span><span class="line"><span class="cl">journalctl -f -u postfix*
</span></span></code></pre></div><div class="footnotes" role="doc-endnotes">
<hr>
<ol>
<li id="fn:1">
<p>You can easily get this with <code>hostname -f</code>.&#160;<a href="#fnref:1" class="footnote-backref" role="doc-backlink">&#x21a9;&#xfe0e;</a></p>
</li>
</ol>
</div>
]]></content><category scheme="taxonomy:tags" term="proxmox" label="proxmox"/><category scheme="taxonomy:tags" term="proxmox-ve" label="proxmox-ve"/><category scheme="taxonomy:tags" term="email" label="email"/><category scheme="taxonomy:tags" term="postfix" label="postfix"/></entry></feed>