我有一个特殊的需求,似乎可以通过 Postfix 实现。
我有 2 个邮件服务器可供使用。
- 第一个是在本地 Linux 服务器中,由 Postfix 和 Dovecot 管理
- 第二个由 gmail (pro) 为某些用户管理(不是 @gmail.com 邮件)
例如我有[电子邮件保护]在本地服务器上,以及[电子邮件保护]通过 gmail 管理。如果我发送电子邮件至[电子邮件保护],本地服务器接管。但如果我发送电子邮件到[电子邮件保护],我希望将这封电子邮件重定向至 Gmail。
目前本地部分运行正常,但是当我尝试发送邮件到[电子邮件保护](gmail 管理的用户),邮件被拒绝:“收件人地址被拒绝:虚拟邮箱表中的用户未知”。
有什么想法吗?这是我的 main.cf 配置(Postfix)
smtpd_banner = $myhostname ESMTP $mail_name (Debian/GNU)
biff = no
append_dot_mydomain = no
readme_directory = no
smtpd_tls_cert_file=/etc/letsencrypt/live/domain.com/fullchain.pem
smtpd_tls_key_file=/etc/letsencrypt/live/domain.com/privkey.pem
smtpd_tls_security_level=may
smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache
smtpd_sasl_auth_enable = yes
smtpd_sasl_type = dovecot
smtpd_sasl_path = private/auth
smtpd_helo_required = yes
smtpd_helo_restrictions = reject_non_fqdn_helo_hostname,reject_invalid_helo_hostname,reject_unknown_helo_hostname
disable_vrfy_command = yes
smtpd_delay_reject = yes
smtpd_recipient_restrictions = permit_sasl_authenticated,permit_mynetworks,reject_unauth_destination,reject_invalid_hostname,reject_non_fqdn_hostname,reject_non_fqdn_sender,reject_non_fqdn_recipient,reject_unknown_sender_domain,reject_rbl_client sbl.spamhaus.org,reject_rbl_client cbl.abuseat.org
smtpd_relay_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination
relay_recipient_maps = hash:/etc/postfix/relay_recipients
transport_maps = hash:/etc/postfix/transport
myhostname = domain.com
alias_maps = hash:/etc/aliases
myorigin = /etc/mailname
mydestination = localhost.ovh.net, localhost
relayhost =
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = all
virtual_mailbox_domains = mysql:/etc/postfix/mysql-virtual-mailbox-domains.cf
virtual_mailbox_maps = mysql:/etc/postfix/mysql-virtual-mailbox-maps.cf
virtual_alias_maps = mysql:/etc/postfix/mysql-virtual-alias-maps.cf
virtual_transport = dovecot
dovecot_destination_recipient_limit = 1
smtpd_milters = inet:localhost:12301 inet:localhost:54321
non_smtpd_milters = inet:localhost:12301 inet:localhost:54321
Relay_recipients 文件的内容:
[email protected]
传输文件的内容
[email protected] relay:[smtp.google.com]:587
* local
是否可以 ?
我的新配置:
smtpd_banner = $myhostname ESMTP $mail_name (Debian/GNU)
biff = no
append_dot_mydomain = no
readme_directory = no
smtpd_tls_cert_file=/etc/letsencrypt/live/maws.fr/fullchain.pem
smtpd_tls_key_file=/etc/letsencrypt/live/maws.fr/privkey.pem
smtpd_tls_security_level=may
smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache
smtpd_sasl_auth_enable = yes
smtpd_sasl_type = dovecot
smtpd_sasl_path = private/auth
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_auth_enable = yes
smtp_sender_dependent_authentication = yes
smtp_use_tls = yes
smtp_tls_CAfile = /etc/postfix/cacert.pem
smtp_sasl_security_options = noanonymous
smtpd_helo_required = yes
smtpd_helo_restrictions = reject_non_fqdn_helo_hostname,reject_invalid_helo_hostname,reject_unknown_helo_hostname
disable_vrfy_command = yes
smtpd_delay_reject = yes
transport_maps = hash:/etc/postfix/transport
smtpd_relay_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination
myhostname = vps42.ovh.net
alias_maps = hash:/etc/aliases
myorigin = /etc/mailname
mydestination = $myhostname localhost.$mydomain localhost $mydomain
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = all
relayhost = [smtp.gmail.com]:587
inet_protocols = ipv4
virtual_mailbox_domains = mysql:/etc/postfix/mysql-virtual-mailbox-domains.cf
virtual_mailbox_maps = hash:/etc/postfix/transport mysql:/etc/postfix/mysql-virtual-mailbox-maps.cf
virtual_alias_maps = mysql:/etc/postfix/mysql-virtual-alias-maps.cf
virtual_transport = dovecot
dovecot_destination_recipient_limit = 1
smtpd_milters = inet:localhost:12301 inet:localhost:54321
non_smtpd_milters = inet:localhost:12301 inet:localhost:54321
传输文件的内容:
[email protected] relay:[smtp.gmail.com]:587
现在当我发送邮件到[电子邮件保护](我的本地用户)它在本地管理。如果我发送邮件到[电子邮件保护](由 gmail 管理)我收到了邮件(胜利!),但它是循环发送的(伤心……):
postfix/smtp[6097]: A601C44494: to=<[email protected]>, relay=smtp.gmail.com[142.251.4.108]:587, delay=2.3, delays=0.38/0.03/1.3/0.51, dsn=2.0.0, status=sent (250 2.0.0 OK 1622552412 j10sm9603207ilk.87 - gsmtp)
postfix/smtp[6097]: 2CC4844494: to=<[email protected]>, relay=smtp.gmail.com[173.194.76.108]:587, delay=1.1, delays=0.42/0/0.3/0.34, dsn=2.0.0, status=sent (250 2.0.0 OK 1622552415 o3sm3206340wrm.78 - gsmtp)
(日志的一小部分,它是发送结果,完整日志:https://mclo.gs/wOo6BFB)
我已经发送了一封邮件[电子邮件保护]到[电子邮件保护],经过一个循环后似乎从[电子邮件保护]到[电子邮件保护]
任何想法 ?
答案1
你的 在哪里relay_domains
?你输入的$mydestination
只是你的本地服务器名称。
根据基本配置自述文件:
重要提示:如果您的机器是整个域的邮件服务器,那么您也必须列出 $mydomain。
Example 2: domain-wide mail server.
/etc/postfix/main.cf:
mydestination = $myhostname localhost.$mydomain localhost $mydomain
如果您不打算指定$myhostname
为 FQDN(默认情况下,Postfix 将$mydomain
通过剥离第一部分来派生),那么您最好不要指定$myhostname
,而是指定$mydomain
,因为 Postfix 将从中为您派生一个主机名(更多信息请参阅基本配置自述文件)。
接下来,对于您的传输文件,您需要确保如果您relay
在传输图中使用,则设置了$relayhost
Gmail 目的地并拥有有效的凭据sasl_passwd
。
本指南包含有关设置的一些有用$relayhost
信息sasl_passwd
:https://www.linuxbabe.com/mail-server/postfix-transport-map-relay-map-flexible-email-delivery
transport_maps
此外,我已经够老派了,如果我要拆分收件人,我也想明确指定我的域:
[email protected] smtp:[smtp.google.com]:587
domain.com local