how to send email in python?
Mark Pilgrim
f8dy at my-deja.com
Tue Feb 6 08:02:37 EST 2001
In article <3A7FA5BA.82FB7593 at esec.com.au>,
Sam Wun <swun at esec.com.au> wrote:
> does anyone knows? I am using python 1.6.
You don't specify which platform you're on, so I won't assume you have
sendmail or anything easy like that, so we'll do it the hard (and
cross-platform) way.
from smtplib import SMTP def sendmail(smtpserver, fromaddr, toaddr, subject,
msg): smtpsock = SMTP(smtpserver) msg = "From: Your name
<%(fromaddr)s\nSubject: %(subject)s\n\n%(msg)s" % vars() rc =
smtpsock.sendmail(fromaddr, [toaddr], msg) smtpsock.quit() return rc
## If your mail server requires POP authentication (like Yahoo! Mail does),
you can't call the above function directly; call this one instead: from
poplib import POP3 def sendmailwithPOPauth(popserver, popuser, poppassword,
smtpserver, fromaddr, toaddr, subject, msg): popsock = POP3(popserver)
popsock.user(popuser) popsock.pass_(poppassword) # note weird function name;
"pass" is reserved word in Python popsock.quit() return
sendmail(smtpserver, fromaddr, toaddr, subject, msg)
Hope this helps.
-M
--
You're smart; why haven't you learned Python yet? http://diveintopython.org/
Sent via Deja.com
http://www.deja.com/
More information about the Python-list
mailing list