我已经设置了 postfix 来通过我的 gmail 帐户中继 proxmox 消息,并使用别名将我所有的根电子邮件转发到外部地址。使用 sendmail 命令时,可以在 gmail 的已发送文件夹中看到电子邮件,收件人:字段为空,密件抄送:是我的外部地址。使用 mail -s 时,可以在 gmail 发送的文件夹中看到电子邮件,其中 To: 字段作为原始根电子邮件,Bcc: 是我的外部地址。
我的转发地址不应该在 To: 字段中替换 [email protected] 而不是 Bcc: 并完全停止发送到 [email protected] 吗?
根电子邮件的测试命令
# echo -e "Subject:Hello World \n\n Testing email\n" | sendmail root
# echo "testing" | mail -s "test message" root
日志文件
Dec 29 12:56:13 pve postfix/pickup[32080]: DB1E662DFA: uid=0 from=<root>
Dec 29 12:56:13 pve postfix/cleanup[32097]: DB1E662DFA: message-id=<[email protected]>
Dec 29 12:56:13 pve postfix/qmgr[32081]: DB1E662DFA: from=<[email protected]>, size=390, nrcpt=1 (queue active)
Dec 29 12:56:13 pve postfix/cleanup[32097]: E13A162DF8: message-id=<[email protected]>
Dec 29 12:56:13 pve postfix/local[32099]: DB1E662DFA: to=<[email protected]>, orig_to=<root>, relay=local, delay=0.04, delays=0.03/0.01/0/0, dsn=2.0.0, status=sent (forwarded as E13A162DF8)
Dec 29 12:56:13 pve postfix/qmgr[32081]: E13A162DF8: from=<[email protected]>, size=515, nrcpt=1 (queue active)
Dec 29 12:56:13 pve postfix/qmgr[32081]: DB1E662DFA: removed
Dec 29 12:56:13 pve postfix/smtp[32100]: connect to smtp.gmail.com[2607:f8b0:4001:c1d::6c]:587: Network is unreachable
Dec 29 12:56:14 pve postfix/smtp[32100]: E13A162DF8: to=<[email protected]>, orig_to=<root>, relay=smtp.gmail.com[74.125.126.109]:587, delay=0.85, delays=0/0.03/0.37/0.45, dsn=2.0.0, status=sent (250 2.0.0 OK 1514570174 f126sm11045770ioa.84 - gsmtp)
Dec 29 12:56:14 pve postfix/qmgr[32081]: E13A162DF8: removed
Dec 29 12:59:40 pve postfix/pickup[32080]: D6C9362DFA: uid=0 from=<root>
Dec 29 12:59:40 pve postfix/cleanup[32429]: D6C9362DFA: message-id=<[email protected]>
Dec 29 12:59:40 pve postfix/qmgr[32081]: D6C9362DFA: from=<[email protected]>, size=280, nrcpt=1 (queue active)
Dec 29 12:59:40 pve postfix/cleanup[32429]: DDD4D62DF8: message-id=<[email protected]>
Dec 29 12:59:40 pve postfix/local[32431]: D6C9362DFA: to=<[email protected]>, orig_to=<root>, relay=local, delay=0.05, delays=0.03/0.01/0/0.01, dsn=2.0.0, status=sent (forwarded as DDD4D62DF8)
Dec 29 12:59:40 pve postfix/qmgr[32081]: DDD4D62DF8: from=<[email protected]>, size=405, nrcpt=1 (queue active)
Dec 29 12:59:40 pve postfix/qmgr[32081]: D6C9362DFA: removed
Dec 29 12:59:41 pve postfix/smtp[32432]: connect to smtp.gmail.com[2607:f8b0:4001:c1d::6c]:587: Network is unreachable
Dec 29 12:59:41 pve postfix/smtp[32432]: DDD4D62DF8: to=<[email protected]>, orig_to=<root>, relay=smtp.gmail.com[74.125.126.109]:587, delay=0.93, delays=0.01/0.02/0.52/0.38, dsn=2.0.0, status=sent (250 2.0.0 OK 1514570381 a69sm13573861itc.18 - gsmtp)
Dec 29 12:59:41 pve postfix/qmgr[32081]: DDD4D62DF8: removed
别名
root: [email protected]
postmaster: root
nobody: root
hostmaster: root
webmaster: root
www:root
主文件
# See /usr/share/postfix/main.cf.dist for a commented, more complete version
myhostname=pve.home.com
smtpd_banner = $myhostname ESMTP $mail_name (Debian/GNU)
biff = no
# appending .domain is the MUA's job.
append_dot_mydomain = no
# Uncomment the next line to generate "delayed mail" warnings
#delay_warning_time = 4h
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
myorigin = /etc/mailname
mydestination = $myhostname, localhost.$mydomain, localhost
#relayhost =
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
mailbox_size_limit = 0
inet_interfaces = loopback-only
recipient_delimiter = +
# sets gmail as relay
relayhost = [smtp.gmail.com]:587
# use tls
smtp_use_tls=yes
# use sasl when authenticating to foreign SMTP servers
smtp_sasl_auth_enable = yes
# path to password map file
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
# list of CAs to trust when verifying server certificate
smtp_tls_CAfile = /etc/ssl/certs/Equifax_Secure_CA.pem
smtp_tls_session_cache_database = btree:/var/lib/postfix/smtp_tls_session_cache
smtp_tls_session_cache_timeout = 3600s
# eliminates default security options which are imcompatible with gmail
smtp_sasl_security_options =
主机
127.0.0.1 localhost.localdomain localhost
127.0.1.1 pve.home.com pve pvelocalhost
# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts
邮件名
pve.home.com
默认情况下不会重写地址;为此,Sendmail 功能是
genericstable
Postfix 调用的generic(5)
,因此理论上添加到您的
main.cf
然后添加条目,/etc/postfix/generic
例如然后运行
postmap /etc/postfix/generic
并重新启动 Postfix 应该会导致地址重写。(这可能会因邮件传输代理(如 Postfix)使用的信封地址与邮件本身中存在的正文地址之间的区别而变得复杂......)在这种
| sendmail
情况下,您应该提供适当的To
地址标头以及Subject
,或者使用邮件用户代理(例如mail
)为您处理这些详细信息。