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 ="[email protected]"
To = ["[email protected]"]
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 [email protected] 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?
_______________________________________________
Tutor maillist - [email protected]
http://mail.python.org/mailman/listinfo/tutor