[FRPythoneers] e-mail from cgi

Sean Reifschneider jafo at tummy.com
Mon Jun 3 12:24:00 MDT 2002

On Mon, Jun 03, 2002 at 12:30:36PM -0600, J. Wayde Allen wrote:
>wondering if there is a recommended way to generate the e-mail?  I was
>just tinkering with the smtplib module, but am not too sure how to use it
>yet.  Is this on the best module to use?

I would do it using popen:

   import os

   fp = os.popen('/usr/sbin/sendmail -t -oi', 'w')
   fp.write('To: <%s>\n' % toAddr)
   fp.write('From: <bob at domain.com>\n')
   fp.write('Subject: Form submission results.\n')
   fp.write('Hi, below you\'ll find the form submission results.\n')

So, as you see, you just dump the headers and the body of the message to
the file pointer and close it.  This assumes that you have a properly
configured mail server (at least for sending outgoing messages) on the
local machine.  If you have to use a remote SMTP server, smtplib is
probably the best way to go.

 "I was on IRC once and got mistaken for Dan Bernstein. I still have
 nightmares."  -- Donnie Barnes
Sean Reifschneider, Inimitably Superfluous <jafo at tummy.com>
tummy.com - Linux Consulting since 1995. Qmail, KRUD, Firewalls, Python

More information about the FRPythoneers mailing list