0

My code is:

import smtplib
server = smtplib.SMTP("smtp.gmail.com",587) #587-> port no
##ALLOWED: https://www.google.com/settings/lesssecureapps
server.starttls()
print("Connected with Gmail Server")
pwd = open("pass.txt").read()
server.login("prateeek.hitman007@gmail.com",pwd)
server.sendmail("prateeek.hitman007@gmail.com","prateekpriyadarshi1328@gmail.com","I miss you 
Prateek")

The Following Output is :

Connected with Gmail Server
Traceback (most recent call last):
  File "E:/Python Edufavrica/Day11/email_backend.py", line 23, in <module>
    server.login("prateeek.hitman007@gmail.com",pwd)
  File "C:\Users\Prateek Priyadarshi\AppData\Local\Programs\Python\Python36-32\lib\smtplib.py", line 730, in login
    raise last_exception
  File "C:\Users\Prateek Priyadarshi\AppData\Local\Programs\Python\Python36-32\lib\smtplib.py", line 721, in login
    initial_response_ok=initial_response_ok)
  File "C:\Users\Prateek Priyadarshi\AppData\Local\Programs\Python\Python36-32\lib\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 h14sm7287809pfq.46 - gsmtp')

Please Help me in resolving this error!!

Barmar
  • 741,623
  • 53
  • 500
  • 612
PrateekHIT
  • 33
  • 1
  • 5
  • The error is pretty clear, the username or password are incorrect. – Barmar Apr 25 '20 at 06:23
  • Try stripping whitespace from the password: `pwd = open("pass.txt").read().strip()` – Barmar Apr 25 '20 at 06:24
  • No, username and password are correct and i stripped whitespace from password and now this error is showing... message = MIMEMultiPart() #message contains the predefined dictionary NameError: name 'MIMEMultiPart' is not defined – PrateekHIT Apr 25 '20 at 06:53
  • Do you have `from email.MIMEMultipart import MIMEMultipart` in your script? – Barmar Apr 25 '20 at 12:26
  • See https://stackoverflow.com/questions/38825943/mimemultipart-mimetext-mimebase-and-payloads-for-sending-email-with-file-atta – Barmar Apr 25 '20 at 12:26
  • I added from email.MIMEMultipart import MIMEMultipart in my script and nothing changed it is showing the same username and password not accepted also I pasted the above code from the link and this error came out : ModuleNotFoundError: No module named 'email.MIMEText' – PrateekHIT Apr 25 '20 at 15:39
  • That has nothing to do with the authentication, it was to fix the error `name MIMEMultipart is not defined` – Barmar Apr 25 '20 at 16:13
  • Yes I added email.MIMEMultipart import MIMEMultipart it is showing error from email.MIMEMultipart import MIMEMultipart ModuleNotFoundError: No module named 'email.MIMEMultipart' then i saw some other fixes someone told to use from email.mime.MIMEMultipart import MIMEMultipart it is showing this error .. from email.mime.MIMEMultipart import MIMEMultipart ModuleNotFoundError: No module named 'email.mime.MIMEMultipart' ... I think there is no function defined for MIMEMultipart in _init_.py – PrateekHIT Apr 27 '20 at 06:00

0 Answers0