472,952 Members | 2,162 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,952 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 2384
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: Mushico | last post by:
How to calculate date of retirement from date of birth
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...

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.