解决方案 1(不是最好的方法)

解决方案 1(不是最好的方法)

我的电子邮件服务器在 ( ) 上运行良好Debian Jessie 8.5。我的设置使用Postfix 2.11.3Dovecot 2.2.13和 使用虚拟用户和邮箱(Maildir 样式)。它运行良好,直到我想实现垃圾邮件文件夹的自动创建并发送通过 标记为垃圾邮件的电子邮件SpamAssassin 3.4.0 / Perl 5.20.2。这工作正常。我可以在我的虚拟域之间收发电子邮件,也可以从外部(Gmail、Yahoo 等)收发电子邮件。我能够在托管在此服务器上的虚拟域之间发送电子邮件。但是当我尝试向外界(Gmail、Yahoo 等)发送电子邮件时,我在 中收到以下信息/var/log/syslog

Nov  8 21:47:08 mercury postfix/smtpd[12803]: connect from localhost[127.0.0.1]
Nov  8 21:47:08 mercury postfix/smtpd[12803]: 93611814E5: client=localhost[127.0.0.1]
Nov  8 21:47:08 mercury postfix/cleanup[12805]: 93611814E5: message-id=<[email protected]>
Nov  8 21:47:08 mercury opendkim[24011]: 93611814E5: DKIM-Signature field added (s=mail, d=example.com)
Nov  8 21:47:08 mercury postfix/qmgr[12250]: 93611814E5: from=<[email protected]>, size=6380, nrcpt=1 (queue active)
Nov  8 21:47:08 mercury spamd[738]: spamd: connection from ip6-localhost [::1]:33575 to port 783, fd 6
Nov  8 21:47:08 mercury spamd[738]: spamd: setuid to vmail succeeded
Nov  8 21:47:08 mercury spamd[738]: spamd: processing message <[email protected]> for vmail:5000
Nov  8 21:47:08 mercury postfix/smtpd[12803]: disconnect from localhost[127.0.0.1]
Nov  8 21:47:15 mercury spamd[738]: spamd: clean message (-1.1/5.5) for vmail:5000 in 7.3 seconds, 6661 bytes.
Nov  8 21:47:15 mercury spamd[738]: spamd: result: . -1 - ALL_TRUSTED,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HTML_MESSAGE,T_REMOTE_IMAGE scantime=7.3,size=6661,user=vmail,uid=5000,required_score=5.5,rhost=ip6-localhost,raddr=::1,rport=33575,mid=<[email protected]>,autolearn=ham autolearn_force=no
Nov  8 21:47:15 mercury postfix/pipe[12806]: 93611814E5: to=<[email protected]>, relay=spamassassin, delay=7.4, delays=0.07/0/0/7.3, dsn=5.1.1, status=bounced (user unknown)
Nov  8 21:47:15 mercury postfix/cleanup[12805]: F10AB814E7: message-id=<[email protected]>
Nov  8 21:47:15 mercury postfix/qmgr[12250]: F10AB814E7: from=<>, size=8521, nrcpt=1 (queue active)
Nov  8 21:47:15 mercury postfix/bounce[12819]: 93611814E5: sender non-delivery notification: F10AB814E7
Nov  8 21:47:15 mercury postfix/qmgr[12250]: 93611814E5: removed
Nov  8 21:47:16 mercury postfix/virtual[12820]: F10AB814E7: to=<[email protected]>, relay=virtual, delay=0.02, delays=0/0.02/0/0, dsn=2.0.0, status=sent (delivered to maildir)
Nov  8 21:47:16 mercury postfix/qmgr[12250]: F10AB814E7: removed
Nov  8 21:47:16 mercury spamd[9376]: prefork: child states: II

底线 - 似乎 Postfix 没有扩展我的/var/postfix/users和/或 Postfix 没有将域/用户传递给 Dovecot,因此产生了这个status=bounced (user unknown)错误。

我的dovecot -n是:

# 2.2.13: /etc/dovecot/dovecot.conf
# OS: Linux 3.16.0-4-amd64 x86_64 Debian 8.5
auth_verbose = yes
base_dir = /var/run/dovecot/
info_log_path = /var/log/dovecot.info
lda_mailbox_autocreate = yes
lda_mailbox_autosubscribe = yes
log_path = /var/log/dovecot
mail_home = /home/vmail/%d/%n
mail_location = maildir:~/
managesieve_notify_capability = mailto
managesieve_sieve_capability = fileinto reject envelope encoded-character vacation subaddress comparator-i;ascii-numeric relational regex imap4flags copy include variables body enotify environment mailbox date ihave
namespace inbox {
  hidden = no
  inbox = yes
  location =
  mailbox Drafts {
    special_use = \Drafts
  }
  mailbox Junk {
    special_use = \Junk
  }
  mailbox Sent {
    special_use = \Sent
  }
  mailbox "Sent Messages" {
    special_use = \Sent
  }
  mailbox Trash {
    special_use = \Trash
  }
  prefix =
  subscriptions = yes
}
passdb {
  args = scheme=PLAIN username_format=%u /etc/dovecot/users
  driver = passwd-file
}
plugin {
  sieve = /etc/dovecot/sieve/default.sieve
  sieve_dir = ~/sieve
}
pop3_uidl_format = %g
postmaster_address = postmaster@${DOMAIN}
protocols = imap pop3
service auth {
  unix_listener /var/spool/postfix/private/auth {
    group = postfix
    mode = 0660
    user = postfix
  }
}
service imap-login {
  inet_listener imaps {
    port = 0
  }
}
ssl = no
ssl_cert = /etc/ssl/dovecot.crt
ssl_key = /etc/ssl/dovecot.key
ssl_parameters_regenerate = 1 days
userdb {
  args = uid=vmail gid=vmail home=/home/vmail/%d/%n
  driver = static
}
userdb {
  args = uid=vmail gid=vmail home=/home/vmail/%d/%n
  driver = static
}
valid_chroot_dirs = /home/vmail/
verbose_ssl = yes
protocol lmtp {
  mail_plugins = " sieve"
}
protocol lda {
  mail_plugins = " sieve"
}

postconf返回:

alias_database = hash:/etc/aliases
alias_maps = hash:/etc/aliases
append_dot_mydomain = no
biff = no
broken_sasl_auth_clients = yes
config_directory = /etc/postfix
home_mailbox = Maildir/
inet_interfaces = all
mailbox_command =
mailbox_size_limit = 0
milter_default_action = accept
milter_protocol = 2
mydestination = fqdn.mydomain.com, mercury, localhost.localdomain, localhost
myhostname = fqdn.mydomain.com
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
myorigin = /etc/mailname
non_smtpd_milters = inet:localhost:12301
queue_directory = /var/spool/postfix
readme_directory = no
recipient_delimiter = +
relayhost =
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl/sasl_passwd
smtp_sasl_security_options = noanonymous
smtp_tls_CApath = /etc/ssl/certs
smtp_tls_cert_file = /etc/ssl/dovecot.crt
smtp_tls_key_file = /etc/ssl/dovecot.key
smtp_tls_loglevel = 1
smtp_tls_security_level = may
smtp_use_tls = yes
smtpd_banner = $myhostname ESMTP $mail_name (Debian/GNU)
smtpd_milters = inet:localhost:12301
smtpd_relay_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination
smtpd_sasl_auth_enable = yes
smtpd_sasl_authenticated_header = yes
smtpd_sasl_path = private/auth
smtpd_sasl_type = dovecot
smtpd_tls_CApath = /etc/ssl/certs
smtpd_tls_cert_file = /etc/ssl/dovecot.crt
smtpd_tls_key_file = /etc/ssl/dovecot.key
smtpd_tls_loglevel = 1
smtpd_tls_protocols = !SSLv2, !SSLv3
smtpd_tls_security_level = may
smtpd_use_tls = yes
spamassassin_destination_recipient_limit = 1
virtual_alias_maps = hash:/etc/postfix/virtual
virtual_gid_maps = static:5000
virtual_mailbox_base = /home/vmail
virtual_mailbox_domains = /etc/postfix/vhosts
virtual_mailbox_maps = hash:/etc/postfix/vmaps
virtual_minimum_uid = 1000
virtual_uid_maps = static:5000

我不知道我应该研究什么来解决这个奇怪的问题。我可以在我的虚拟域之间发送电子邮件,我可以接收电子邮件,但我无法向世界发送任何电子邮件 :-(

答案1

解决方案 1(不是最好的方法)

打开你的master.cf,并搜索以下规则:

smtp       inet  n       -       y       -       -       smtpd
smtps      inet  n       -       y       -       -       smtpd
submission inet  n       -       y       -       -       smtpd

在这些规则之后,您可能会看到-o content_filter=spamassassin
这对于接收邮件很有用,但对于发送邮件则不需要。如果您使用 dovecat 来处理邮件,它甚至不起作用,这就是问题所在。

解决方案是:仅对传入邮件使用 spamassasin 过滤器。
您可以通过仅将其应用于规则smtp而不是smtpsand来实现此目的submission
与此相反,您不能使用端口 25 发送邮件,但这是个问题吗?大多数 ISP 无论如何都会阻止它,端口 465/587 更适合这种情况。

解决方案 2(更好的方法)

在您的master.cf文件中,删除(或注释)spamassassin 的行。

main.cf你添加这个:

virtual_transport = lmtp:unix:private/dovecot-lmtp

在您的 dovecot 配置文件(20-lmtp.conf 或 dovecot.conf)中,您为 lmtp 流量启用 sieve 插件(您已经拥有这个,但我不知道它是否在引号内工作):

protocol lmtp {
  mail_plugins = sieve
}

这也需要在 dovecot 配置文件中:

protocols = imap pop3 lmtp sieve

你没有这最后两个。

使用此解决方案,本地邮件将由 dovecot 处理(并且将执行筛选),外发邮件将被中继。

最后一部分是垃圾邮件过滤。
这是通过邮件过滤器(而不是服务)完成的。

如果你还没有这个,请安装它:apt-get install spamass-milter
在你的 postfix 中main.cf,通过添加以下内容来启用它:

smtpd_milters = inet:localhost:12301 unix:spamass/spamass.sock

它应该使用您已经配置的 spamassassin 规则。

答案2

好吧,可能够简单了,但是对于我来说,我有以下内容/etc/postfix/master.cf

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}

我将其改为:

spamassassin unix -     n   n   -   -   pipe
    flags=DROhu user=vmail:vmail argv=/usr/bin/spamc -f -e
    /usr/sbin/sendmail -oi -f ${sender} ${recipient}

并重新启动 postfix 并service postfix restart开始工作:-)

相关内容