简体   繁体   中英

Giving error when trying to send a email with smtplib in python 3.8.3

I gives me a error when I run the program or try to update smtplib. This is the error:

Here is the picture

I am using python 3.8.3. Any help would be greatly appreciated!

Here is my code:

# from your Gmail account  
import smtplib 

# list of email_id to send the mail 
li = ["example2@gmail.com(email)", "example3@outlook.com(email)"] 

for dest in li: 
    s = smtplib.SMTP('smtp.gmail.com', 587) 
    s.starttls() 
    s.login("example1@gmail.com(email)", "example1(password)") 
    message = "Message_you_need_to_send"
    s.sendmail("example1@gmail.com(email)", dest, message) 
    s.quit() 

Here is the error:

Traceback (most recent call last):
  File "d:/Auto_Email/Auto_Email3.py", line 16, in <module>
    server.login(username,password)
  File "C:\Users\drake\AppData\Local\Programs\Python\Python38\lib\smtplib.py", line 734, in login
    raise last_exception
  File "C:\Users\drake\AppData\Local\Programs\Python\Python38\lib\smtplib.py", line 723, in login
    (code, resp) = self.auth(
  File "C:\Users\drake\AppData\Local\Programs\Python\Python38\lib\smtplib.py", line 646, 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 d9sm5982379qtq.56 - gsmtp')



PS D:\Auto_Email> pip install update smtplib
Collecting update
  Using cached update-0.0.1-py2.py3-none-any.whl (2.9 kB)
ERROR: Could not find a version that satisfies the requirement smtplib (from versions: none)
ERROR: No matching distribution found for smtplib

I have already tried to update smtplib (show above) and tried different usernames and passwords and all give me the same error. I have also allowed access on my google account.

If you are still having problems you need to first go to the google accounts security setting and allow unsecured apps to access the account. 那个设定

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM