473,322 Members | 1,718 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

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 2394
hi,

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..
http://pypi.python.org/pypi/mailer
Dec 7 '12 #2
dwblas
626 Expert 512MB
Also, Python has the SMPT module. Doug Hellmann's page is one place for more info.
Dec 8 '12 #3

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

Similar topics

12
by: Marc Ederis | last post by:
Hello, I'm having a problem with sending data with sockets over a dial-up connection. When I use the send function, it will happily send a buffer of a megabyte and more in one shot. But of...
20
by: Simon Harvey | last post by:
Festive greetings fellow programmers! I've been programming now for about 4, maybe 5 years now. 4 of those years were at university so and I havent had much work experience of making real world...
2
by: Asit | last post by:
How can i know when user clicks X button of the browser ? I have to write some code when user clicks X button of browser. What is the event for capturing this event ? Help needed ASAP. Asit
3
by: Kiki | last post by:
Hello, i wonder if anyone can help.. Is there a way of knowing from the parent window (var window;) that the child window (var newWindow) has been closed? i can't touch the child window's closed...
2
by: palaga | last post by:
hi I'm using QueueUserWorkItem to execute a bunch of tasks using the thread pool. Once started, I would like to wait for all of them to finish, using something like WaitAll. Is there a way I can...
1
by: Bullfrog1870 | last post by:
Hello: How do I know when to use 'New' when declaring a variable? How do I know when an instance can be created? Ex: Dim x As New System.Random -versus- Dim mailMessage As...
4
by: jiang.haiyun | last post by:
Hello all, when i import SOAPpy, the python crashed and print out 'usage:copy source destination'. As follows: ############################ haiyun# python Python 2.4.1 (#2, Mar 28 2006,...
10
by: =?Utf-8?B?UHVjY2E=?= | last post by:
Hi, I'm using vs2005 and .net 2.0. I started 2 threadpool threads. How do I know when they're done with their tasks? Thanks. ThreadPool.QueueUserWorkItem(new...
1
by: Sin Jeong-hun | last post by:
Microsoft.DirectX.DirectSound.SecondaryBuffer buff=new ... .... buff.Play(0,data,BufferPlayFlags.Default); The play method seems to be asynchronous. Then how can I know when it finished playing...
8
by: AAaron123 | last post by:
If IE is open I'd like my app to receive an event or otherwise know when IE receives a mouse click. Is that fairly easy to do? Thanks in advance
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.