Sending e-mail with python 1.5.2

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Andrew McLean

    Sending e-mail with python 1.5.2

    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
  • Paul Rubin

    #2
    Re: Sending e-mail with python 1.5.2

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

    Comment

    • Andrew McLean

      #3
      Re: Sending e-mail with python 1.5.2

      Thanks. smtplib was what I was looking for.

      In article <7xisjrsox7.fsf @ruckus.brouhah a.com>, Paul Rubin
      <http@?.cx.inva lid> writes[color=blue]
      >I thought 1.5.2 had the smtp package. If not, how about just using
      >popen to send the mail through /bin/mail.[/color]

      --
      Andrew McLean

      Comment

      • Richard van de Stadt

        #4
        Re: Sending e-mail with python 1.5.2

        Andrew McLean wrote:[color=blue]
        >
        > 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[/color]

        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(Lo calMailServer)
        #mail.set_debug level(1)
        mail.sendmail(f romaddr, email_recipient s_tuple, message % locals())
        mail.quit()
        except:
        print 'Could not send email!'

        ---

        Richard.

        Comment

        Working...