Sending e-mail with python 1.5.2

A

Andrew McLean

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.
 
P

Paul Rubin

I thought 1.5.2 had the smtp package. If not, how about just using
popen to send the mail through /bin/mail.
 
A

Andrew McLean

Thanks. smtplib was what I was looking for.

Paul Rubin said:
I thought 1.5.2 had the smtp package. If not, how about just using
popen to send the mail through /bin/mail.
 
R

Richard van de Stadt

Andrew said:
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.

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!'
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,176
Messages
2,570,950
Members
47,500
Latest member
ArianneJsb

Latest Threads

Top