how to send email in python?

Mark Pilgrim f8dy at my-deja.com
Tue Feb 6 09:10:13 EST 2001


In article <95osl9$vds$1 at nnrp1.deja.com>,
  Mark Pilgrim <f8dy at my-deja.com> wrote:
> 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.
>

OK, let's try this again, this time with !@#$% hard line breaks:

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
  popsock.quit()
  return sendmail(smtpserver, fromaddr, toaddr, subject, msg)

-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