Quantcast
Channel: Active questions tagged email - Stack Overflow
Viewing all articles
Browse latest Browse all 29762

How can I send mail using python script?

$
0
0

For doing this I started following the link New to Python, GMail SMTP error. And my code is

import smtplib

sender = "noreply@gmail.com"
receiver = ["ram@gmail.com"]
message = "Hello!"

try:
    session = smptlib.SMTP('smtp.gmail.com',587)
    session.ehlo()
    session.starttls()
    session.ehlo()
    session.login(sender,'mypassword')
    session.sendmail(sender,receiver,message)
    session.quit()

except smtplib.SMTPException:
    print('Error')

But I am getting the following error:

Traceback (most recent call last):
  File "email2.py", line 1, in <module>
    import smtplib
  File "/usr/lib/python2.7/smtplib.py", line 46, in <module>
    import email.utils
  File "/home/ramkrishna/test/email.py", line 17, in <module>
    except SMTPException:
NameError: name 'SMTPException' is not defined

Viewing all articles
Browse latest Browse all 29762

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>