Gmail 阻止通过 SMTP 发送电子邮件? [复制]

Posted

技术标签:

【中文标题】Gmail 阻止通过 SMTP 发送电子邮件? [复制]【英文标题】:Gmail is blocking to send email via SMTP? [duplicate] 【发布时间】:2020-12-13 01:28:47 【问题描述】:

我试图从这个问题php+Ubuntu Send email using gmail form localhost 设置msmtp 服务器。所以我设置了default(帐户)发送自:

/etc/msmtprc:

defaults
tls on
tls_starttls on
tls_trust_file /etc/ssl/certs/ca-certificates.crt
account default
host smtp.gmail.com
port 587
auth on
user autak987@gmail.com
password PASSWORD #not real password
from autak987@gmail.com
logfile /var/log/msmtp.log

现在,当我尝试发送测试电子邮件时(以 root 身份执行):

echo -e "Subject: Test Mail\r\n\r\nThis is my first test email." | msmtp --debug --from=default -t autak987@gmail.com

给予:

loaded system configuration file /etc/msmtprc
ignoring user configuration file /root/.msmtprc: No such file or directory
falling back to default account
using account default from /etc/msmtprc
host = smtp.gmail.com
port = 587
source ip = (not set)
proxy host = (not set)
proxy port = 0
timeout = off
protocol = smtp
domain = localhost
auth = choose
user = autak987@gmail.com
password = *
passwordeval = (not set)
ntlmdomain = (not set)
tls = on
tls_starttls = on
tls_trust_file = /etc/ssl/certs/ca-certificates.crt
tls_crl_file = (not set)
tls_fingerprint = (not set)
tls_key_file = (not set)
tls_cert_file = (not set)
tls_certcheck = on
tls_min_dh_prime_bits = (not set)
tls_priorities = (not set)
auto_from = off
maildomain = (not set)
from = default
add_missing_from_header = on
add_missing_date_header = on
remove_bcc_headers = on
dsn_notify = (not set)
dsn_return = (not set)
logfile = /var/log/msmtp.log
logfile_time_format = (not set)
syslog = (not set)
aliases = (not set)
reading recipients from the command line and the mail
<-- 220 smtp.gmail.com ESMTP o60sm9122564eda.30 - gsmtp
--> EHLO localhost
<-- 250-smtp.gmail.com at your service, [2a00:1028:8d1b:f32a:baac:e4e8:de4:df3c]
<-- 250-SIZE 35882577
<-- 250-8BITMIME
<-- 250-STARTTLS
<-- 250-ENHANCEDSTATUSCODES
<-- 250-PIPELINING
<-- 250-CHUNKING
<-- 250 SMTPUTF8
--> STARTTLS
<-- 220 2.0.0 Ready to start TLS
TLS session parameters:
    (TLS1.3)-(ECDHE-X25519)-(ECDSA-SECP256R1-SHA256)-(AES-256-GCM)
TLS certificate information:
    Owner:
        Common Name: smtp.gmail.com
        Organization: Google LLC
        Locality: Mountain View
        State or Province: California
        Country: US
    Issuer:
        Common Name: GTS CA 1O1
        Organization: Google Trust Services
        Country: US
    Validity:
        Activation time: Tue 11 Aug 2020 10:57:38 AM CEST
        Expiration time: Tue 03 Nov 2020 09:57:38 AM CET
    Fingerprints:
        SHA256: 8A:D6:DC:62:1D:6B:BB:B9:45:03:38:E8:40:AC:8C:A8:60:75:CF:B6:95:93:83:4C:ED:AD:BA:CA:71:47:44:E7
        SHA1 (deprecated): 84:5D:7F:E9:0E:7C:6A:C0:70:F6:04:09:4A:1C:AA:5D:6C:BF:11:E2
--> EHLO localhost
<-- 250-smtp.gmail.com at your service, [2a00:1028:8d1b:f32a:baac:e4e8:de4:df3c]
<-- 250-SIZE 35882577
<-- 250-8BITMIME
<-- 250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH
<-- 250-ENHANCEDSTATUSCODES
<-- 250-PIPELINING
<-- 250-CHUNKING
<-- 250 SMTPUTF8
--> AUTH PLAIN AGF1dGFrOTg3QGdtYWlsLmNvbQBNaWxhbmJhcm9zMTIz
<-- 535-5.7.8 Username and Password not accepted. Learn more at
<-- 535 5.7.8  https://support.google.com/mail/?p=BadCredentials o60sm9122564eda.30 - gsmtp
msmtp: authentication failed (method PLAIN)
msmtp: server message: 535-5.7.8 Username and Password not accepted. Learn more at
msmtp: server message: 535 5.7.8  https://support.google.com/mail/?p=BadCredentials o60sm9122564eda.30 - gsmtp
msmtp: could not send mail (account default from /etc/msmtprc)
msmtp: cannot log to /var/log/msmtp.log: cannot open: Permission denied
msmtp: log info was: host=smtp.gmail.com tls=on auth=on user=autak987@gmail.com from=default recipients=autak987@gmail.com smtpstatus=535 smtpmsg='535-5.7.8 Username and Password not accepted. Learn more at\n535 5.7.8  https://support.google.com/mail/?p=BadCredentials o60sm9122564eda.30 - gsmtp' errormsg='authentication failed (method PLAIN)' exitcode=EX_NOPERM

所以日志显示&lt;-- 535-5.7.8 Username and Password not accepted. Learn more at,但我收到了一封警告电子邮件someone has tried to log in your account,我确认是我。然后它说The application you have tried to use, Google blocked, because it does not fulfil our security standards。那么msmtp 不符合安全标准?我已经下载了所有需要的证书(并且凭据是正确的登录名或密码)。那么如果msmtp 不符合安全标准,我该如何从 php 表单发送电子邮件?

【问题讨论】:

您是否尝试为不太安全的应用启用 Access 【参考方案1】:

您可能需要在您的 Google 帐户中启用安全性较低的应用程序以允许使用 smtp https://support.google.com/accounts/answer/6010255?hl=en

如果您使用 2 因素身份验证,则需要生成应用专用密码 https://support.google.com/accounts/answer/185833?hl=en

【讨论】:

以上是关于Gmail 阻止通过 SMTP 发送电子邮件? [复制]的主要内容,如果未能解决你的问题,请参考以下文章

通过 Mandrill 到 Gmail

通过 smtp.gmail.com 发送 php 邮件连接

为什么设计不通过gmail smtp发送电子邮件?

Django 通过 smtp.gmail.com 发送电子邮件的问题

通过 Gmail SMTP 发送电子邮件时出错

通过 smtp(gmail 服务器)发送邮件 [重复]