Python SMTPAuthnticationError [英] Python SMTPAuthnticationError

查看:194
本文介绍了Python SMTPAuthnticationError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

直到昨天,我都没有问题使用python发送电子邮件,但由于某种原因,我遇到了以下错误.

Up until yesterday I had no issue sending emails with python and now for some reason I am getting the following error.

Traceback (most recent call last):
  File "main.py", line 20, in <module>
    mail(name)
  File "/home/runner/mail.py", line 26, in mail
    smtpserver.login(gmail_user, gmail_password)
  File "/usr/local/lib/python3.7/smtplib.py", line 730, in login
    raise last_exception
  File "/usr/local/lib/python3.7/smtplib.py", line 721, in login
    initial_response_ok=initial_response_ok)
  File "/usr/local/lib/python3.7/smtplib.py", line 642, in auth
    raise SMTPAuthenticationError(code, resp)
smtplib.SMTPAuthenticationError: (535, b'5.7.8 Username and Password not accepted. Learn more at\n5.7.8  https://support.google.com/mail/?p=BadCredentials p17sm967082ils.71 - gsmtp')

我已经使用下面的代码大约4个月了,并且没有任何问题.这是我用来访问gmail的代码:

I have been using the below code for about 4 months and haven't had any issues. Here is the code I am using to access gmail:

import smtplib

def mail(name):
    gmail_user = 'email@gmail.com'
    gmail_password = 'password'

    emaillist = ['email@email.com']

    for email in emaillist:
        sent_from = gmail_user
        to = email
        subject = 'Subject'

        body = "Body"

        email_text = '''\
        From: %s
        To: %s
        Subject: %s

        %s
        '''%(sent_from, to, subject, body)

        try:
            server = smtplib.SMTP_SSL('smtp.gmail.com', 465)
            server.ehlo()
            server.login(gmail_user, gmail_password)
            server.sendmail(sent_from, to, body)
            server.close()

            print('Email sent!')
        except:
            print('Oops!')

我尝试更改gmail中使用不安全的应用程序,启用IMAP并更改电子邮件帐户的密码.到目前为止,解决问题没有运气.任何帮助将不胜感激.

I have tried changing the use less secure apps in gmail, enabling IMAP, and changing the password for the email account. So far no luck with solving the issue. Any help would be greatly be appreciated.

推荐答案

Google增强了其安全策略,我邀请您阅读以下部分的链接:安全应用程序少&您的Google帐户,然后打开以下链接(安全性较低的应用访问权限)

Google has increased its security policies, I invite you to read this link in the part of: Less secure apps & your Google Account and open the link like bellow ( Less secure app access)

https://support.google.com/accounts/answer/6010255

稍后允许访问不安全的应用程序:是

later Allow access to unsafe applications: YES

这篇关于Python SMTPAuthnticationError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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