Python 2.7 在Python2.7中使用Gmail的问题

Python 2.7 在Python2.7中使用Gmail的问题,python-2.7,gmail,Python 2.7,Gmail,新来的人。。。。 我已经在这个网站上搜索过了,并尝试了多种代码变体,但当我尝试使用Python2.7通过Gmail发送电子邮件时,仍然收到一个登录错误。我已经在我的Gmail帐户上启用了“不太安全的应用程序”功能,但我仍然收到此错误: 回溯(最近一次呼叫最后一次): 文件“T:\OC\Projects\Aquadat\Scripting\rawarcpyscript\sendmailwithattachment_Aquadat.py”,第28行,在 svr.登录(发件人,pwd) 文件“C:\P

新来的人。。。。 我已经在这个网站上搜索过了,并尝试了多种代码变体,但当我尝试使用Python2.7通过Gmail发送电子邮件时,仍然收到一个登录错误。我已经在我的Gmail帐户上启用了“不太安全的应用程序”功能,但我仍然收到此错误:

回溯(最近一次呼叫最后一次): 文件“T:\OC\Projects\Aquadat\Scripting\rawarcpyscript\sendmailwithattachment_Aquadat.py”,第28行,在 svr.登录(发件人,pwd) 文件“C:\Python27\ArcGIS10.3\lib\smtplib.py”,第615行,登录 引发SMTPAuthenticationError(代码,resp) SMTPAuthenticationError:(534,'5.7.14请通过web浏览器登录,\n5.7.14然后重试。\n5.7.14有关详细信息,请访问\n5.7.14 z33sm11383168qta.48-gsmtp')

下面是有问题的代码。我从这个网站上获取了很多信息,并试图使其适应我的应用程序。任何帮助都将不胜感激

import smtplib
from os.path import basename
from email.mime.application import MIMEApplication
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.utils import COMMASPACE, formatdate

svr = smtplib.SMTP_SSL('smtp.gmail.com',465)
svr.ehlo()
svr.starttls()
svr.ehlo()
sender = 'my_name'
pwd = 'my_pwd'
svr.login(sender,pwd)
rcvr = sender #Change to arcpy.GetParameterAsText(x) when working
def send_mail(send_from,send_to,subject,text,files,
              server):
    assert isinstance(send_to, list)

    msg = MIMEMultipart()
    msg['From'] = send_from
    msg['To'] = COMMASPACE.join(send_to)
    msg['Date'] = formatdate(localtime=True)
    msg['Subject'] = subject

    msg.attach(MIMEText(text))

    for f in files or []:
        with open(f, "rb") as fil:
            part = MIMEApplication(
                fil.read(),
                Name=basename(f)
            )
            part['Content-Disposition'] = 'attachment; filename="%s"' % basename(f)
            msg.attach(part)


        smtp = smtplib.SMTP_SSL(server)
    smtp.sendmail(send_from, send_to, msg.as_string())
    smtp.close()

可能有用的,可能有用的,可能重复的,可能有用的,可能重复的