【发布时间】:2018-05-07 04:57:27
【问题描述】:
我正在尝试使用以下简单的 python 和邮件客户端通过 Google SMTP 服务器发送电子邮件。
我对 Google 将此脚本标记为不安全并要求我允许不太安全的应用程序访问发件人的 gmail 帐户的部分感到有些困惑。
有什么方法可以解决这个问题,而不必让不太安全的应用程序访问我的 gmail 帐户。
#Make necessary imports
import mailclient
#Craft the message
msg = mailclient.Message("This will be the subject", "This will be the body content", 'sender@gmail.com', 'recipient@domain.com')
#Create server object with gmail
s = mailclient.Server('smtp.gmail.com', '587', 'sender@gmail.com', 'senderpassword', True)
#Send email
s.send(msg)
【问题讨论】:
-
它与代码无关。您需要在 google 帐户中启用它。参考 - support.google.com/accounts/answer/6010255?hl=en
-
我认为可以使用其他邮件客户端,而无需在帐户上启用不太安全的应用程序。我应该在代码中包含哪些内容才能不被标记?
-
在代码级别对 Google 无能为力。尝试使用 Outlook 或业务 smtp 服务器凭据。
标签: python email gmail smtplib