Aayush Dip Giri
Aayush Dip Giri

Reputation: 17

Sending multiple email using python

When I try to send multiple email using python I get this error

Traceback (most recent call last):
  File "emailsend.py", line 28, in <module>
    server.login('[email protected]', '*****')
  File "C:\Python37\lib\smtplib.py", line 730, in login
    raise last_exception
  File "C:\Python37\lib\smtplib.py", line 721, in login
    initial_response_ok=initial_response_ok)
  File "C:\Python37\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 h3sm11216819pji.9 - gsmtp')

Here is my python code.Even though my password is correct, it is throwing authentication error

subject="BloodNepal ask you for your help now"
sameMessage='Subject: {}\n\n{}'.format(subject,message)
fromMail='[email protected]'
context = ssl.create_default_context()
with smtplib.SMTP_SSL("smtp.gmail.com", 465, context=context) as server:
    server.login('[email protected]', *******)
    with open("emailsend.csv") as file:
        reader = csv.reader(file)
        next(reader)  # Skip header row
        for name, phoneNo, email in reader:
            server.sendmail(
                fromMail,
                email,
                sameMessage,
            )

Upvotes: 1

Views: 89

Answers (1)

user12520850
user12520850

Reputation:

Your code is fine, but Google limits you. Try to enable the "Access for less secure apps" in the settings:

https://www.google.com/settings/security/lesssecureapps

It may take some time until you can send emails after enabling.

This should solve your issue :-)

Upvotes: 1

Related Questions