Sending e-mail with python 1.5.2

Richard van de Stadt stadt at borbala.com
Sat Jan 24 11:23:37 EST 2004


Andrew McLean wrote:
> 
> I am writing a CGI script on an account that only has Python 1.5.2. It's
> principal purpose is to take some user input from a form, do some
> manipulation and return some information to the user. However, I would
> also like it to send some information to an e-mail account (behind the
> scenes).
> 
> The e-mail could be quite simple, but I wouldn't rule out wanting to
> send a pickled object or two.
> 
> Now if I was using a recent Python I would just use the email package,
> but I don't think it's compatible with v1.5.2. I know I have access to
> the sendmail binary, so something should be possible. Any pointers
> gratefully received.
> 
> --
> Andrew McLean

This should help to get you going:

message = """\
Message-ID: <%(messageID)s>
Subject: %(subject)s
Date: %(date)s
From: %(fromstring)s <%(fromaddr)s>
Reply-To: %(fromaddr)s
X-Mailer: Python smtplib
%(to_cc_list)s

%(body)s
"""
try:
    mail = smtplib.SMTP(LocalMailServer)
    #mail.set_debuglevel(1)
    mail.sendmail(fromaddr, email_recipients_tuple, message % locals())
    mail.quit()
except:
    print 'Could not send email!'

---

Richard.



More information about the Python-list mailing list