[boston-pig] Email error
Andrew Robert
andrew.arobert at gmail.com
Fri Sep 8 15:33:06 MDT 2006
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Brook, Robert wrote:
> Can anyone explain the inconsistent error that I get with this email code
>
> import smtplib
> fromaddress='robert.brook at domain.com'
> toaddress='robert.brook at domain.com'
> msg="subject: Hello\n\n\This is the body of the message."
> a=smtplib.SMTP('HostName',25)
> a.sendmail(fromaddress,toaddress,msg)
> a.quit()
>
>
> If I run this code interactively it works.
>
> I if make it into a email.py file I get the error message
>
> AttributeError: 'module' object has no attribute 'SMTP'
>
> Thanks in advance
>
>
>
>
>
> _______________________________________________
> boston-pig mailing list
> boston-pig at wingware.com
> http://wingware.com/mailman/listinfo/boston-pig
>
Try using something like this.
def send(serverURL, sender, to, subject, text):
"""
Form and send an e-mail message
"""
import smtplib
headers = "From: %s\r\nTo: %s\r\nSubject: %s\r\n\r\n" % (sender, to, subject)
message = headers + text
mailServer = smtplib.SMTP(serverURL) # replace serverURL with site specific mail server
mailServer.sendmail(sender, to, message)
mailServer.quit()
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (MingW32)
Comment: GnuPT 2.7.2
iD8DBQFFAeGSDvn/4H0LjDwRAgw2AKCLWnGbbgT4sdw46QqPHM1YjJt2rACfWAqR
VE+0VXEY9/Xcg/z/iQZm9TA=
=/uj8
-----END PGP SIGNATURE-----
More information about the boston-pig
mailing list