从python 3.4脚本发送电子邮件,而无需在gmail中启用“安全性较低的应用" [英] sending email from python 3.4 script, WITHOUT enabling 'less secure apps' in gmail

查看:51
本文介绍了从python 3.4脚本发送电子邮件,而无需在gmail中启用“安全性较低的应用"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用python 3.4脚本从我的gmail地址发送邮件.我使用以下代码:

  import smtplibdef sendmail():sender='myemail@gmail.com'收件人= ['someone@gmail.com']message =此处的文字"尝试:session = smtplib.SMTP('smtp.gmail.com',587)session.ehlo()session.starttls()session.ehlo()session.login(sender,'mypassword')session.sendmail(发送方,接收方,消息)session.quit()除了smtplib.SMTPException:打印(错误,无法发送邮件!") 

如果我在我的gmail帐户中允许安全性较低的应用程序",则该脚本可以正常运行.但是,如果我禁用了安全性较差的应用",则无法正常工作(我收到了来自Google的警告电子邮件,登录尝试被阻止").我想修改我的代码,以便能够在不启用此功能的情况下发送邮件.

我已经阅读了有关类似问题的所有问题和答案,但是没有找到任何有用的答案或方法.有人对此有解决方案吗?

解决方案

来自允许不太安全的应用访问您的帐户"支持页面

Google可能会阻止某些不使用现代安全标准的应用或设备的登录尝试.

登录名/密码不是现代的身份验证机制.您应该实现 SASL XOAuth2 .

i would like to send mail using a python 3.4 script, from my gmail address. i use the following code:

import smtplib  

def sendmail():  
    sender='myemail@gmail.com'  
    receiver=['someone@gmail.com']  
    message='text here'  
    try:  
        session=smtplib.SMTP('smtp.gmail.com',587)  
        session.ehlo()  
        session.starttls()  
        session.ehlo()  
        session.login(sender,'mypassword')  
        session.sendmail(sender,receiver,message)  
        session.quit()  
    except smtplib.SMTPException:  
        print('Error, can not send mail!')

if i 'allow less secure apps' in my gmail account, the script works fine. however, if i disable 'less secure apps', it doesn't works (i get a warning email from google, with 'sign-in attempt blocked') . i would like to modify my code, to be able to send mail without enabling this thing.

i have read all the questions and answers regarding similar problems, but did not find any useful answers or methods. someone has any solution for this?

解决方案

From "Allowing less secure apps to access your account" support page

Google may block sign in attempts from some apps or devices that do not use modern security standards.

A login/password is not a modern mechanism to authenticate. You should implement SASL XOAuth2.

这篇关于从python 3.4脚本发送电子邮件,而无需在gmail中启用“安全性较低的应用"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆