def send_email(user, pwd, recipient, subject, body):
import smtplib
gmail_user = user
gmail_pwd = pwd
FROM = user
TO = ['dhe*****@***.com']
SUBJECT = subject
TEXT = body
# Prepare actual message
message = """\From: %s\nTo: %s\nSubject: %s\n\n%s
""" % (FROM, ", ".join(TO), SUBJECT, TEXT)
server = smtplib.SMTP("smtp.gmail.com", 587)
server.ehlo()
server.starttls()
server.login(gmail_user, gmail_pwd)
server.sendmail(FROM, TO, message)
server.close()
print 'successfully sent the mail'
if __name__ == '__main__':
send_email('abc@gmail.com', 'password', '', 'Hello', 'hello')
我正在使用此脚本从abc@gmail.com发送电子邮件。 (暂时硬编码收件人)
但我得到了
smtplib.SMTPAuthenticationError:(534,' 5.7.14 https://accounts.google.com/signin/ ..... 请通过网络浏览器和\ n5.7.14登录,然后重试。\ n5.7.14了解更多信息,请访问\ n5.7.14 https://support.google.com/mail/answer/78754 dl17sm699785obc.9 - gsmtp')
已为该帐户(abc@gmail.com)启用了安全性较低的应用访问权限。 该帐户也没有2因素身份验证。
我无法通过该计算机上的网络浏览器登录,因为它是EC2实例。我该怎么办?