I am trying to send email (Gmail) using python, but I am getting following error:
'AttributeError: module 'ssl' has no attribute '_create_stdlib_context'
My code:
def send_email(self):
username = '****@gmail.com'
password = '****'
sent_to = '****@gmail.com'
msg = "Subject: this is the trail subject..."
server = smtplib.SMTP_SSL("smtp.gmail.com", 465)
server.login(username, password)
server.sendmail(username, sent_to, msg)
server.quit()
print('Mail Sent')
The following is the error:
/usr/local/bin/python3.8 /Users/qa/Documents/Python/python-api-testing/tests/send_report.py
Traceback (most recent call last):
File "/Users/qa/Documents/Python/python-api-testing/tests/send_report.py", line 23, in <module>
email_obj.send_email()
File "/Users/qa/Documents/Python/python-api-testing/tests/send_report.py", line 11, in send_email
server = smtplib.SMTP_SSL("smtp.gmail.com", 465)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/smtplib.py", line 1031, in __init__
context = ssl._create_stdlib_context(certfile=certfile,
AttributeError: module 'ssl' has no attribute '_create_stdlib_context'
Start of /Users/qa/Documents/Python/python-api-testing/tests/send_report.py