[Tutor] Sending an email alert

Marc marc at marcd.org
Fri Aug 28 21:00:17 CEST 2009


Hello,

 

I am trying to code an email alert and am running into the following error:

Connecting to server

Traceback (most recent call last):

  File "C:\Users\Marc1\Documents\Python\email test\email.py", line 1, in
<module>

    import smtplib

  File "C:\Python26\lib\smtplib.py", line 46, in <module>

    import email.utils

  File "C:\Users\Marc1\Documents\Python\email test\email.py", line 12, in
<module>

    s = smtplib.SMTP('smtp.marcd.org')

AttributeError: 'module' object has no attribute 'SMTP'

 

The code I am trying to use is:

 

import smtplib

import time

>From ="me at mydomain.org"

To = ["me at mydomain.org"]

Date = time.ctime(time.time())

Subject = "Email Python Test"

Text = "It Works!!"

mMessage = ('From %s\nTo: %s\nDate: %s\nSubject: %s\n%s\n' % (From, To,
Date, Subject, Text))

print 'Connecting to server'

s = smtplib.SMTP('smtp.mydomain.org')

rCode = s.sendmail(From, To, mMessage)

s.quit()

if rCode:

   print 'Error sending message'

else:

   print 'message sent'

 

Of course, I am substituting me at mydoamin.org with my email address and
'smtp.mydomain.org' with my domain email server.

 

The error seems to say that the method or function SMTP does not exist
within smtplib, but if I run the lines

 

import smtplib

s = smtplib.SMTP('smtp.mydomain.org')

 

in IDLE, it connects and then times out, as I would expect.

I tried this on Windows and Linux with the same result.

 

Thanks,

Marc

 

What am I missing here?

 

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20090828/08848b1d/attachment.htm>


More information about the Tutor mailing list