18

我已经在我的 centos 5.10 上安装了 postfix、dovecot、Clamav、Spamassassin 和 amavisd-new。教程在这里:http ://catatanlepas.com/komputer/aplikasi/server-mail/postfix/359-instalasi-postfix-menggunakan-dovecot-di-centos-5-5

我只是没有在该教程中安装 Razor、Pyzor、dan DCC。

在 /var/log/maillog 中一切正常,如果有垃圾邮件没有进入收件箱,但我想将垃圾邮件移动到垃圾邮件文件夹。

我的问题是: 1. 如何在我的网络邮件上自动创建垃圾邮件文件夹,因为它只是创建收件箱、草稿和已发送邮件,而且我的网络邮件上没有垃圾邮件文件夹。2. 如何将垃圾邮件移动到每个用户的垃圾邮件文件夹(我在 /var/vmail 上创建用户)

请帮助我,我在谷歌搜索了 5 天,我对此很感兴趣:(

谢谢你。

4

3 回答 3

39

I - 将您的电子邮件发送设置为使用 Dovecot LDA:

OP 链接的原始网站处于脱机状态,但我相信电子邮件传递是通过sendmail程序进行的,它应该通过 Dovecot LDA 完成,以满足您的需要。(为了避免电子邮件来源标题更改)。

编辑 Postfix 的master.cf(开头):

smtp      inet  n       -       -       -       -       smtpd -o content_filter=spamassassin

在文件末尾:

spamassassin unix -     n   n   -   -   pipe
    flags=DROhu user=vmail:vmail argv=/usr/bin/spamc -f -e 
    /usr/lib/dovecot/deliver -f ${sender} -d ${user}@${nexthop} 

现在编辑 Postfixmain.cf并添加(可选,检查 (3) 波纹管):

spamassassin_destination_recipient_limit = 1

现在您的电子邮件将通过 Dovecot LDA 发送,无需更改标题。对于好奇的人,这里有一些关于我的配置的细节:

  1. 配置可与加地址/子地址/收件人分隔符一起使用(发往的电子邮件user+nospam@example.com将被发送到user@example.com收件箱) - 这就是为什么我添加-d ${user}@${nexthop}这将删除+域之前的所有内容。要启用此功能,请务必添加recipient_delimiter = +main.cf;
  2. 我的标志flags=DROhu,它们没有添加任何异常但可以在这里理解:http ://www.postfix.org/pipe.8.html ;
  3. spamassassin_destination_recipient_limit = 1需要确保每个收件人都被 spamassassin 单独处理。由于D上面的标志(包括X-Original-To标题),这是必需的。如果您不关心此标头,则可以删除该标志,这不是必需的。

II - 将您的垃圾邮件移动到Junk文件夹:

(在https://stackoverflow.com/a/32470349/560745的@Electronic Technologies 的帮助下)

您还可以将 Dovecot 配置为将检测为垃圾邮件的电子邮件移动到JunkIMAP 文件夹。请按照以下说明操作:

  1. 编辑/etc/dovecot/conf.d/15-mailboxes.conf并取消注释/添加Junk文件夹(应该在namespace inbox附近的部分mailbox Trash):

    mailbox Junk {
       special_use = \Junk
    }
    
  2. 安装;dovecot-sieve_apt-get install dovecot-sieve

  3. 编辑/etc/dovecot/conf.d/90-sieve.conf并注释该行:#sieve = ~/.dovecot.sieve

  4. 编辑/etc/dovecot/conf.d/90-plugin.conf为:

    plugin {
        sieve = /etc/dovecot/sieve/default.sieve
    }
    
  5. 编辑/etc/dovecot/conf.d/15-lda.conf/etc/dovecot/conf.d/20-lmtp.conf匹配:

    protocol lda/lmtp { # do not copy/paste this line!
      mail_plugins = $mail_plugins sieve
    }
    

    警告:您可能在protocol选择项下还有其他设置,请保留它们。文件中的行protocol lda/lmtp更改,保留原件。

  6. 创建文件夹/etc/dovecot/sieve/

  7. 使用以下内容创建文件/etc/dovecot/sieve/default.sieve

    require "fileinto";
    if header :contains "X-Spam-Flag" "YES" {
        fileinto "Junk";
    }
    
  8. 将文件夹权限更改为您的虚拟电子邮件用户和组,例如:chown vmail:vmail /etc/dovecot/sieve/ -R. 如果你错过了这个鸽舍会抱怨!

  9. 重启一切:service postfix restart; service dovecot restart; service spamassassin restart

  10. 尝试向服务器上的某些电子邮件(从外部服务器)发送电子邮件,首先是普通电子邮件,然后是另一个具有以下主题的电子邮件:XJS*C4JDBQADN1.NSBN3*2IDNEN*GTUBE-STANDARD-ANTI-UBE-TEST-EMAIL*C.34X. 第二封电子邮件应该进入Junk文件夹,第一封电子邮件应该进入您的收件箱。

如果这在您第一次尝试时不起作用,请查看日志:tail -f /var/log/mail.log并在tail运行时发送电子邮件。一个好的工作设置应该报告stored mail into mailbox 'INBOX'stored mail into mailbox 'Junk'.

于 2016-01-02T23:37:42.580 回答
7

对于 Dovecot 2.1+ 修改 /etc/dovecot/dovecot.conf:

namespace {
    type = private
    separator = .
    inbox = yes
  mailbox Trash {
    auto = subscribe # autocreate and autosubscribe
    special_use = \Trash
  }
  mailbox Drafts {
    auto = subscribe
    special_use = \Drafts
  }
  mailbox Sent {
    auto = subscribe
    special_use = \Sent
  }
  mailbox Junk {
    auto = subscribe
    special_use = \Junk
  }
}

plugin {
    sieve = /home/spam/default.sieve
}

protocol lda {
            auth_socket_path = /var/run/dovecot/auth-master
            mail_plugins = $mail_plugins sieve
}

然后 /etc/postfix/master.cf - 添加

spamassassin unix -     n   n   -   -   pipe
  user=vmail argv=/usr/bin/spamc -f -e  /usr/libexec/dovecot/deliver -f ${sender} -d ${recipient}

(!!) user=vmail - 将用户更改为为 spamassassin 设置的用户

并将内容过滤器添加到 smtp

smtp  inet  n  - - - -  smtpd -o content_filter=spamassassin

在 /etc/mail/spamassassin/local.cf

add_header all Status _YESNO_, score=_SCORE_ required=_REQD_ version=_VERSION_
#rewrite_header Subject *****SPAM*****
bayes_ignore_header X-Bogosity
bayes_ignore_header X-Spam-Flag
bayes_ignore_header X-Spam-Status

我将在邮件中添加 X-Spam 标头,用于以后的筛子过滤重新启动 spamassassin,重新加载 dovecot 和 postfix

垃圾文件夹将自动创建。所有垃圾邮件都将在本地发送到邮箱垃圾

我还添加了一个筛子过滤器的示例,以将所有标记为垃圾邮件(上面的 spamassassin 配置)移动到垃圾文件夹。

require "fileinto";
  if exists "X-Spam-Flag" {
          if header :contains "X-Spam-Flag" "NO" {
          } else {
          fileinto "Junk";
          stop;
          }
  }
于 2015-09-09T03:14:40.200 回答
0

嗯,有几种方法,但这是我发现的工作。在你安装好 postfix、dovecot、spamassassin 和(我推荐 procmail)之后,你可以告诉 procmail/spamassassin 如何将垃圾邮件分发到不同的文件夹中。带鸽舍。我使用以下 4 个文件夹:

spam          (for known spam based on Bayes setting)
spam-learn    (for spam that slipped through, you move it here)
spam-probably (for spam ID'd as probably spam by Bayes setting)
spam-unlearn  (messages flagged as spam, that are NOT spam go here)

将文件夹 setup 和 postfix 配置为通过 procmail 过滤邮件:

mailbox_command = /usr/bin/procmail -a "$EXTENSION"

您现在可以设置您的 procmailrc 以将垃圾邮件放在收件箱中的正确位置。你的 ~/.procmailrc 应该是这样的:

PATH=/usr/bin/vendor_perl:/usr/bin:/bin:/usr/local/bin:.
MAILDIR=$HOME/Mail/
LOGDIR=$HOME/log
#DEFAULT=$HOME/Mail/
LOGFILE=$LOGDIR/procmail.log
VERBOSE=ON
## with spamc
:0fw: spamc.lock
* < 256000
| spamc
#| /usr/bin/vendor_perl/spamc
# Mails with a score of 15 or higher are almost certainly spam (with 0.05%
# false positives according to rules/STATISTICS.txt). Let's put them in a
# different mbox. (This one is optional.)
:0:
* ^X-Spam-Level: \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
spam
#Mail/spam

# All mail tagged as spam (eg. with a score higher than the set threshold)
# is moved to "probably-spam".
:0:
* ^X-Spam-Status: Yes
spam-probably
#Mail/spam-probably

# Work around procmail bug: any output on stderr will cause the "F" in "From"
# to be dropped.  This will re-add it.
:0
* ^^rom[ ]
{
LOG="*** Dropped F off From_ header! Fixing up. "

:0 fhw
| sed -e '1s/^/F/'
}

现在,使其全部自动运行的最后一个关键是使用fetchmail扫描邮件,当它们到达您的收件箱时,将它们移交给 procmail,以将垃圾邮件/垃圾邮件可能放在正确的文件夹中,并阅读垃圾邮件中的邮件(删除)和spam-unlearn(学习为ham)。一个典型的 fetchmail 脚本是你的 ~/.fetchmailrc。它只包含轮询邮箱的命令:

poll mail.yourserver.com protocol IMAP : user yourname with password yourpass ssl \
sslfingerprint "D9:73:1A:FE:C6:7C:E7:9B:F1:31:F8:A1:A0:E1:F9:27"

(您可以通过简单fetchmail --verbose地对 .fetchmailrc 文件运行来获取服务器指纹,它将打印服务器指纹,检查您当前的指纹,告诉您它们不匹配并关闭连接 - 但是 - 您刚刚获得了正确的指纹下次:-)

最后,通过阅读 spam-learn 和 spam-unlearn 文件夹来设置几个 cron 作业来运行整个过程。每小时就够了。该脚本可能如下所示:

#!/bin/bash

## log file location and per-user name
LDIR=/home/admin/log
LFN="${LDIR}/${USER}.log"

## Retrieve and Process Spam & Ham from 'spam-learn' & 'spam-unlearn' folders
/usr/bin/fetchmail -a -s -n --folder spam-learn -m '/usr/bin/vendor_perl/sa-learn --spam' &>/dev/null
mss=$?
sleep 2
/usr/bin/fetchmail -a -s -n --folder spam-unlearn -m '/usr/bin/vendor_perl/sa-learn --ham' &>/dev/null
mhs=$?

## test and create log dir in noexist
[[ -d "$LDIR" ]] || mkdir -p "$LDIR"
if [[ -w "$LDIR" ]]; then

## check return from fetchmail and write log info
if [[ $(($mhs+$mss)) -le 2 ]]; then
    echo "$(date +'%b %e %R:%S') $HOSTNAME ${0##*/}: sa-learn completed successfully for user $USER" >>$LFN
else
    echo "$(date +'%b %e %R:%S') $HOSTNAME ${0##*/}: sa-learn FAILED for user $USER" >>$LFN
fi
fi

而 cron 作业只需​​执行上面的 spamv.sh 文件:

05 * * * * /usr/local/bin/spamv.sh

我已经运行这样的服务器近十年了,它运行良好。培训文件位于用户的主目录中,可以轻松地逐个移动,为新用户提供良好的基础集。祝你好运。几年前,我为openSuSE 11.0做了一个简短的操作指南。那里可能还有更多信息。

PS Rayzor 值得加载。

于 2014-06-17T05:38:32.707 回答