iredmail-doc/html_bk/pipe.incoming.email.for.cer...

95 lines
4.8 KiB
HTML

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Pipe incoming email for certain user to external script</title>
<link rel="stylesheet" type="text/css" href="./css/markdown.css" />
</head>
<body>
<div id="navigation">
<a href="https://www.iredmail.org" target="_blank">
<img alt="iRedMail web site"
src="./images/logo-iredmail.png"
style="vertical-align: middle; height: 30px;"
/>&nbsp;
<span>iRedMail</span>
</a>
&nbsp;&nbsp;//&nbsp;&nbsp;<a href="./index.html">Document Index</a></div><h1 id="pipe-incoming-email-for-certain-user-to-external-script">Pipe incoming email for certain user to external script</h1>
<div class="toc">
<ul>
<li><a href="#pipe-incoming-email-for-certain-user-to-external-script">Pipe incoming email for certain user to external script</a><ul>
<li><a href="#configure-postfix-to-use-your-external-script-as-transport">Configure Postfix to use your external script as transport</a></li>
<li><a href="#update-per-user-transport-to-use-this-new-transport">Update per-user transport to use this new transport</a></li>
</ul>
</li>
</ul>
</div>
<p>This tutorial explains how to pipe incoming email for certain user to an
external script (it must be a file on your mail server, not a remote file
accessible via ssh/http/ftp/...).</p>
<h2 id="configure-postfix-to-use-your-external-script-as-transport">Configure Postfix to use your external script as transport</h2>
<p>To pipe incoming emails to external script, you must add your external script
as Postfix transport program. Please add below line at the bottom of Postfix
config file <code>/etc/postfix/master.cf</code>:</p>
<pre><code>external-pipe unix - n n - - pipe
flags=DRhu user=vmail:vmail argv=/path/to/your/external/script.sh
</code></pre>
<p><strong>Note</strong>:</p>
<ul>
<li>You can use some macros to replace with corresponding information from the
Postfix queue manager delivery request. Refer to Postfix manual page
<a href="http://www.postfix.org/pipe.8.html">pipe(8)</a> for more details. For example:</li>
</ul>
<pre><code>external-pipe unix - n n - - pipe
flags=DRhu user=vmail:vmail argv=/path/to/your/external/script.sh -f ${sender} -d ${user}@${domain} -m ${extension}
</code></pre>
<ul>
<li>the second line needs to be right under the first line and must start with
one (or more) whitespace, and the first line cannot start with whitespace,
otherwise postfix will fail with <code>unexpected command-line argument</code> errors.
Also make sure the <code>user=</code> line is pointing to a valid user with permissions
to execute the script. This user must not be the postfix or root user, otherwise
or the pipe will fail.</li>
</ul>
<p>Now restart Postfix service to make this new transport available:</p>
<pre><code># /etc/init.d/postfix restart
</code></pre>
<h2 id="update-per-user-transport-to-use-this-new-transport">Update per-user transport to use this new transport</h2>
<p>We need to update per-user transport setting, so that all emails delivered to
this user will be piped to this new transport - your script.</p>
<ul>
<li>
<p>If you have iRedAdmin-Pro:</p>
<ul>
<li>For iRedAdmin-Pro OpenLDAP edition, please go to user profile page, under
tab <code>Advanced</code>, set <code>Relay/Transport setting</code> to <code>external-pipe</code>. Screenshot:</li>
</ul>
</li>
</ul>
<p><img alt="" src="./images/iredadmin/user_profile_relay.png" /></p>
<pre><code>* For iRedAdmin-Pro MySQL or PostgreSQL edition, please go to user profile
page, under tab `Relay`, set `Relay/Transport setting` to `external-pipe`.
</code></pre>
<ul>
<li>
<p>If you don't have iRedAdmin-Pro, please update LDAP/MySQL/PgSQL database to
use this new transport.</p>
<ul>
<li>
<p>For OpenLDAP backend, please login to phpLDAPadmin, add new attribute
<code>mtaTransport</code> for your user, set its value to <code>external-pipe</code>.</p>
</li>
<li>
<p>For MySQL/PostgreSQL backend, please execute below command with SQL
command line tool (Replace 'user@domain.ltd' by the real email address):</p>
</li>
</ul>
</li>
</ul>
<pre><code>sql&gt; USE vmail;
sql&gt; UPDATE mailbox SET transport='external-pipe' WHERE username='user@domain.ltd';
</code></pre>
<p>That's all.</p><div class="footer">
<p style="text-align: center; color: grey;">All documents are available in <a href="https://github.com/iredmail/docs/">GitHub repository</a>, and published under <a href="http://creativecommons.org/licenses/by-nd/3.0/us/" target="_blank">Creative Commons</a> license. You can <a href="https://github.com/iredmail/docs/archive/master.zip">download the latest version</a> for offline reading. If you found something wrong, please do <a href="https://www.iredmail.org/contact.html">contact us</a> to fix it.</p>
</div></body></html>