У меня есть следующая запись в / etc / postfix / virtual:
v2@mydomain.org tibor@mydomain.org, tracking@works-organiser.com
tracking@works-organiser.com tracking.tracking@localhost
Следующая запись в / etc / aliases, которая пересылает электронное письмо на команда:
tracking.tracking: |"/usr/local/v2_mail/v2/script/email_handler.sh"
Эта конфигурация отлично работает , если почта отправляется на (скрытый) локально с почтового сервера (доставляется через службу dovecot), но не отправляется с удаленный сервер (доставляется через службу spamassassin). Во втором случае сообщение возвращается (пользователь неизвестен) . Похоже, что spamassassin ничего не знает о / etc / aliases. Как я могу решить эту проблему?
Журнал сообщения, отправленного с удаленного сервера через почтовый сервер, spamassassin запущен:
Sep 18 09:39:21 zg-3 postfix/smtpd[29296]: B7905A7318: client=zg-2.mydomain.org[94.231.88.101]
Sep 18 09:39:21 zg-3 postfix/cleanup[29301]: B7905A7318: message-id=<20190918074001.CFB7B40CDF@v2.zg-2.mydomain.org>
Sep 18 09:39:21 zg-3 postfix/qmgr[24943]: B7905A7318: from=<v2@mydomain.org>, size=1427, nrcpt=3 (queue active)
Sep 18 09:39:21 zg-3 postfix/pipe[29477]: B7905A7318: to=<tibor.nagy@mydomain.org>, orig_to=<v2@mydomain.org>, relay=spamassassin, delay=0.2, delays=0.01/0.01/0/0.18, dsn=2.0.0, status=sent (delivered via spamassassin service)
Sep 18 09:39:22 zg-3 postfix/pipe[29479]: B7905A7318: to=<tracking.tracking@localhost>, orig_to=<v2@mydomain.org>, relay=spamassassin, delay=0.43, delays=0.01/0.02/0/0.4, dsn=5.1.1, status=bounced (user unknown)
Sep 18 09:39:22 zg-3 postfix/bounce[29486]: B7905A7318: sender non-delivery notification: 2BBCAA731F
Sep 18 09:39:22 zg-3 postfix/qmgr[24943]: B7905A7318: removed
Журнал сообщения, отправленного локально с почтового сервера, spamassassin не запускается:
Sep 18 09:53:46 zg-3 postfix/pickup[29998]: 07DADA7318: uid=0 from=<root@zg-3.mydomain.org>
Sep 18 09:53:46 zg-3 postfix/cleanup[30146]: 07DADA7318: message-id=<20190918075346.07DADA7318@zg-3.mydomain.org>
Sep 18 09:53:46 zg-3 postfix/qmgr[24943]: 07DADA7318: from=<root@zg-3.mydomain.org>, size=399, nrcpt=3 (queue active)
Sep 18 09:53:46 zg-3 postfix/pipe[30466]: 07DADA7318: to=<tibor.nagy@mydomain.org>, orig_to=<v2@mydomain.org>, relay=dovecot, delay=0.05, delays=0.01/0.01/0/0.02, dsn=2.0.0, status=sent (delivered via dovecot service)
Sep 18 09:53:46 zg-3 postfix/local[30147]: 07DADA7318: to=<tracking.tracking@localhost>, orig_to=<v2@mydomain.org>, relay=local, delay=0.45, delays=0.01/0/0/0.43, dsn=2.0.0, status=sent (delivered to command: /usr/local/v2_mail/v2/script/email_handler.sh)
Sep 18 09:53:46 zg-3 postfix/qmgr[24943]: 07DADA7318: removed
Мой main.cf:[12225ptingMy master.cf:[12226 impression
Проблема в том, что dovecot (не spamassassin) как локальный агент доставки (LDA) имеет понятия не имею о / etc / aliases. Поэтому я решил реализовать свой собственный LDA в виде простого сценария оболочки:
#!/bin/bash
# This script started by spamassassin (spamc) as defined in /etc/postfix/master.cf:
# spamassassin unix - n n - - pipe
# flags=DROhu user=vmail:vmail argv=/usr/bin/spamc -f -e /usr/local/mail/script/lda.sh ${sender} ${user}@${nexthop}
#
# So the first argument is the "from address", the 2nd is the "to address".
# If the "to address" is in format address@localhost and address is a line in /etc/aliases, and
# aliased to /usr/local/v2_mail/v2/script/email_handler.sh, than do the forwarding here
# otherwise forward to /usr/lib/dovecot/deliver or to /usr/bin/sendmail
# depending on local or remote delivery
#
# This workaround is necessary because dovecot has no idea about /etc/aliases
shopt -s extglob
if [[ "$2" =~ "@localhost" ]]; then
# Get address without "@localhost"
ADDRESS=${2%%*(@localhost)}
# Look for that line in /etc/aliases
LINE=`grep "^$ADDRESS: |\"/usr/local/v2_mail/v2/script/email_handler.sh" /etc/aliases`
if [ $? -eq 0 ]; then
# Line found, extract and run the command
CMD=${LINE//$ADDRESS: |\"/}
CMD=${CMD//\"/}
# Log the command execution
echo v2_lda.sh: $CMD
exec $CMD
fi
fi
# Local or remote delivery
if [[ "$2" =~ "@mydomain.org" ]] || [[ "$2" =~ "@mymail.com" ]] || [[ "$2" =~ "@localhost" ]]
then
# DO FURTHER PROCESSING OF /etc/aliases HERE IF YOU HAVE MORE
# ENTRIES IN IT
# Log the command execution
echo v2_lda.sh: /usr/lib/dovecot/deliver -f $1 -d $2
/usr/lib/dovecot/deliver -f $1 -d $2
exit $?
else
# Log the command execution
echo v2_lda.sh: /usr/sbin/sendmail -f $1 $2
/usr/sbin/sendmail -f $1 $2
exit $?
fi
Этот сценарий находится в /usr/local/mail/script/lda.sh. Итак, я изменил строку spamassassin в master.cf:[1297pting