I wanted to send a mail with attachment, so first I was trying to send mail using python 3.6 and using pycharm IDE. Every time while running the file I get the following exception.
Traceback (most recent call last): File "/home/UDHAV.MOHATA/script/test.py", line 11, in <module> import smtplib File "/usr/lib/python3.6/smtplib.py", line 47, in <module> import email.utils File "/usr/lib/python3.6/email/utils.py", line 28, in <module> import random File "/home/UDHAV.MAHATA/script/random.py", line 1, in <module> import urllib3 ModuleNotFoundError: No module named 'urllib3' Sample code:
import smtplib import ssl subject = "An email with attachment from Python" body = "This is an email with attachment sent from Python" sender_email = "***********" receiver_email = "***************" password = "********" message = """\ Subject: Hi there This message is sent from Python.""" context = ssl.create_default_context() with smtplib.SMTP_SSL_PORT("smtp.gmail.com", 465, context=context) as server: server.login(sender_email, password) server.sendmail(sender_email, receiver_email, message) Exact python version: 3.6.9
My motive is to send a mail with an attachment. If anyone knows the fix for this import exception or another way. Please let me know.