470,863 Members | 1,185 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,863 developers. It's quick & easy.

Email Via Python so i know when i get an error

Hi all,
I would like to send an email from my Gmail account using python so when i have an error ill receive an auto email. At current the program handles the errors internally and keeps trying to do its task. That part is fine but when it hits an error I would like to receive an email. So i did some googling and found this nice script

Expand|Select|Wrap|Line Numbers
  1. import smtplib
  2. fromaddr = 'my email'
  3. toaddrs = 'to my email'
  4. msg = 'Test Email message'
  5. #provide gmail user name and password
  6. username = 'username'
  7. password = 'password'
  8. # functions to send an email
  9. server = smtplib.SMTP('smtp.googlemail.com:465')
  10. server.ehlo()
  11. server.starttls()
  12. server.ehlo()
  13. server.login(username,password)
  14. server.sendmail(fromaddr, toaddrs, msg)
  15. server.quit()
but i get an error

Expand|Select|Wrap|Line Numbers
  1. Traceback (most recent call last):
  2.   File "C:\email.py", line 1, in <module>
  3.     import smtplib
  4.   File "C:\Python27\lib\smtplib.py", line 46, in <module>
  5.     import email.utils
  6.   File "C:\email.py", line 11, in <module>
  7.     server = smtplib.SMTP('smtp.googlemail.com:465')
  8. AttributeError: 'module' object has no attribute 'SMTP'
So I have checked the Lib folder and Smtplib.py is there and so is the email folder and the utils.py file.

Can anyone help ?

Cheers Shane

P.s using winblows
Dec 6 '12 #1
2 2325

It was quite difficult to connect the gmail server for send and receiving the mails via python instead if you have an outlook account it is possible send email using python...

if you want the gmail account mail's to the outlook email address follow the below setting...
login to your gmail account and select the settings and in the that select forwarding and pop/imap and in that give the outlook email address and use the below python script for sending outlook emails....
Expand|Select|Wrap|Line Numbers
  1. import mailer
  2. import time
  3. import datetime
  4. from datetime import datetime
  5. message = mailer.Message()
  6. message.From = "example@example.com"
  7. message.To = "example@example.com"
  8. message.Subject = "test"
  9. message.Body = "This is automated mail please don't reply to this mail."
  10. mailer = mailer.Mailer('use the server address.com')
  11. mailer.send(message)
  12. print "sent"
for the mailer package download go to the below address..
Dec 7 '12 #2
626 Expert 512MB
Also, Python has the SMPT module. Doug Hellmann's page is one place for more info.
Dec 8 '12 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

12 posts views Thread by Marc Ederis | last post: by
1 post views Thread by Bullfrog1870 | last post: by
1 post views Thread by Sin Jeong-hun | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.