我正在尝试让 gmail 从我的虚域发送电子邮件 - 可以理解,它希望使用为该域设置的 SMTP 服务器。我尝试将 postfix 配置为我的虚域的 SMTP 服务器,但在 gmail 中我不断收到身份验证错误。我的经验似乎与Postfix 作为 Gmail 的 SMTP 服务器非常相似。(“以” google 选项发送邮件) 对于这个特定问题,我在网上几乎没有找到其他有用的信息。大多数其他似乎询问此问题的用户都会得到“这是如何将 gmail 用作 SMTP 服务器”的答案,这显然没有帮助。Gmail 无法从我的虚域发送,这就是我(和它)需要 SMTP 服务器的原因。
这是我的配置文件,我使用 host.example.com 作为运行后缀的服务器的完整主机和域名。- 我已将 vanity.domain 用作我试图以不同用户身份使用 gmail 和 user1 等的虚荣域名。
我添加了 Letsencrypt 证书,因为有人建议 gmail 可能会拒绝自签名证书。我不知道这是否正确,或者我是否做得正确——我在 host.domain.com 上使用了 certbot --apache——证书在 host.exmaple.com 的浏览器中确实有效。
顺便说一句,我还没有设法让后缀使用端口 587 - 所以我从配置中的 [vanity.domain]:587 中删除了 :587 。
main.cf(由于不同指南建议添加的所有内容,它变得很长)
# See /usr/share/postfix/main.cf.dist for a commented, more complete version
# Debian specific: Specifying a file name will cause the first
# line of that file to be used as the name. The Debian default
# is /etc/mailname.
#myorigin = /etc/mailname
smtpd_banner = $myhostname ESMTP $mail_name (Ubuntu)
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
readme_directory = no
# See http://www.postfix.org/COMPATIBILITY_README.html -- default to 2 on
# fresh installs.
compatibility_level = 2
# TLS parameters
smtpd_tls_cert_file=/etc/letsencrypt/live/host.example.com/fullchain.pem
#smtpd_tls_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem
smtpd_tls_key_file=/etc/letsencrypt/live/host.example.com/privkey.pem
#smtpd_tls_key_file=/etc/ssl/private/ssl-cert-snakeoil.key
smtpd_use_tls=yes
smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache
# See /usr/share/doc/postfix/TLS_README.gz in the postfix-doc package for
# information on enabling SSL in the smtp client.
smtpd_relay_restrictions = permit_mynetworks permit_sasl_authenticated defer_unauth_destination
myhostname = host.example.com
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
myorigin = /etc/mailname
mydestination = $myhostname, host.example.com, host, localhost.localdomain, localhost
#relayhost =[vanity.domain]:587
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = all
inet_protocols = all
virtual_alias_domains = vanity.domain
virtual_alias_maps = hash:/etc/postfix/virtual
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noplaintext,noanonymous
smtp_sasl_tls_security_options = noanonymous
smtp_sasl_auth_enable = yes
smtp_use_tls = yes
smtp_tls_CAfile = /etc/ssl/certs/ca-certificates.crt
#smtp_tls_security_level = may
#smtp_tls_protocols = !SSLv2, !SSLv3
#smtp_tls_mandatory_protocols = !SSLv2, !SSLv3
#smtp_tls_mandatory_ciphers = high
smtpd_sasl_type = dovecot
smtpd_sasl_path = private/auth
smtpd_sasl_local_domain =
smtpd_sasl_security_options = noanonymous
broken_sasl_auth_clients = yes
smtpd_sasl_auth_enable = yes
smtpd_recipient_restrictions = permit_sasl_authenticated,permit_mynetworks,reject_unauth_destination
smtp_tls_security_level = may
smtpd_tls_security_level = may
smtp_tls_note_starttls_offer = yes
smtpd_tls_loglevel = 1
smtpd_tls_received_header = yes
smtp_tls_security_level = may
smtp_tls_protocols = !SSLv2, !SSLv3
smtp_tls_mandatory_protocols = !SSLv2, !SSLv3
smtp_tls_mandatory_ciphers = high
smtp_tls_loglevel = 1
sender_canonical_maps = tcp:127.0.0.1:10001
sender_canonical_classes = envelope_sender
recipient_canonical_maps = tcp:127.0.0.1:10002
recipient_canonical_classes = envelope_recipient
等/后缀/虚拟:
[email protected] [email protected]
[email protected] [email protected]
[email protected] [email protected]
[email protected] [email protected]
@vanity.domain [email protected]
我尝试连接时的日志(已删除 ips、日期和时间):
connect from mail-ua1-f41.google.com
Anonymous TLS connection established from mail-ua1-f41.google.com: TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)
warning: mail-ua1-f41.google.com: SASL PLAIN authentication failed:
lost connection after AUTH from mail-ua1-f41.google.com
disconnect from mail-ua1-f41.google.com ehlo=2 starttls=1 auth=0/1 commands=3/4
sasl_passwd
[vanity.domain] user1:longpassword
最后,在 gmail 的 SMTP 设置中,我填写以下内容:
smtp 服务器:host.example.com 用户:user1(我也试过 [email protected] 和 [email protected] - 我不确定应该是哪个) 密码:longpassword 端口:25(试过 587 和 465太)安全性:TLS(尝试过 SSL 并且不安全)