I maintain a domain as a virtual mail domain using Dovecot. I established an address within that domain as an outgoing list address. Say, list@mydomain.com
.
The first step is done by the Dovecot Sieve extension. The .dovecot.sieve
file in the mail folder of the list@mydomain.com
account contains the following:
if not anyof (
header :contains ["from"] ["MAILER-DAEMON"],
header :contains ["auto-submitted"] ["failure"]
) {
redirect "mydomain-list@localhost";
}
keep;
This ensures that all original messages (but not those already redirected or those that failed delivery) are rerouted to a sendmail alias.
Originally, the aliases file just contained the list user addresses. But this led to two problems. First, the sender address remained the original sender address. This could lead to rejection, since my server is not authorized to send e-mail that appears to come, for instance, from a gmail or Yahoo! user. Second, a simple reply would send a reply to the sender only; a "reply all" in turn would send two copies to the sender, one directly, one through the mailing list.
This is what I was trying to avoid when I changed the solution as follows. First, the revamped aliases file now contains the following line:
mydomain-list: "|/usr/bin/procmail -m /etc/mail/mydomain-list.procmail"
The real meat, however, is in that procmail file. Its structure is a tad complicated because it was necessary to a) ensure that all single quotes, double quotes and other metacharacters are properly escaped, but also that b) procmail does not try to invoke a shell, since it runs under a restricted account with no shell access:
CMDA="echo \"\\\"My Domain on behalf of \`formail -zxFrom: | sed -n 's/.*<\(.*\)>.*/\1/p'\`\\\" <list@mydomain.com>\""
CMDB="echo \"\\\"My Domain on behalf of \`formail -zxFrom:\`\\\" <list@mydomain.com>\""
U1="user@some.domain user@other.domain"
U2=user@third.domain
:0
* ^From:.*<.*>
{
FROM_EMAIL=`/bin/sh -c "$CMDA"`
}
:0 E
{
FROM_EMAIL=`/bin/sh -c "$CMDB"`
}
:0 fw
| formail -I"From: $FROM_EMAIL" \
-A"Reply-To: list@mydomain.com" \
-A"Sender: `formail -zxFrom:`"
:0
|/usr/sbin/sendmail -oi -f list@mydomain.com $U1 $U2
This is it. I am sure there are other ways but the result works for me and I avoided having to install a third-party mailing list manager that would require care and feeding on its own.