Re: need help with nullmailer-inject in python cgi script to send attachements ?

2005-03-24 Thread tvmaly
Thank you Denis

  Ty

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: need help with nullmailer-inject in python cgi script to send attachements ?

2005-03-24 Thread Denis S. Otkidach
On 24 Mar 2005 05:20:06 -0800 [EMAIL PROTECTED] wrote:

TC> Due to the restrictions I have at my host, I cannot use smtplib in
TC> my email cgi script.  They gave me a script they use that calls
TC> nullmailer-inject.   I am trying to figure out how to add the
TC> ability to send attachments via the nullmailer-inject call.  I could
TC> not find much documentation on google about nullmailer.  Has anyone
TC> used it before to send attachments?   Here is function  I have so
TC> far that sends a regular email.  The variables like recipient are
TC> set from a cgi in another part of the script.
[...]
TC>   mailfl=os.popen('/usr/bin/nullmailer-inject -f '+fromaddr,'w')
TC>   mailfl.write('To: '+recipient+nl)
TC>   if fromaddr: mailfl.write('From: '+fromaddr+nl)
TC>   mailfl.write('Subject: %s%s\n\n'%(subject,uri))
TC>   mailfl.write(intro)
TC>   rx=0
TC>   prev=''
TC>   for x in cap:
TC> while (rx   if reql[rx]<>prev:
TC> putln(reql[rx],mailfl)
TC>   rx=rx+1
TC> putln(x,mailfl)
TC> prev=x
TC> 
TC>   for x in envl:
TC> mailfl.write('%s: %s\n'%(x,env[x]))
TC>   mailfl.close()

Use email package. Something like the following (untested):

from email.MIMEText import MIMEText
msg = MIMEText(body)
msg['Subject'] = ...
msg['From'] = ...
msg['To'] = ...

from email.MIMEBase import MIMEBase
attachment = MIMEBase('application', 'octet-stream')
attachment.set_payload(open(filename, 'rb').read())
attachment.add_header('Content-Disposition', 'attachment', 
  filename=filename)
from email.Encoders import encode_base64
encode_base64(attachment)
msg.attach(attachment)

# using popen is unsafe if we can't trust fromaddr, using subprocess
from subprocess import Popen, PIPE
mailfl = Popen(['/usr/bin/nullmailer-inject',  '-f', fromaddr],
   stdin=PIPE)
mailfl.stdin.write(msg.as_string())
mailfl.stdin.close()
mailfl.wait()

-- 
Denis S. Otkidach
http://www.python.ru/  [ru]
-- 
http://mail.python.org/mailman/listinfo/python-list


need help with nullmailer-inject in python cgi script to send attachements ?

2005-03-24 Thread tvmaly
Due to the restrictions I have at my host, I cannot use smtplib in my
email cgi script.  They gave me a script they use that calls
nullmailer-inject.   I am trying to figure out how to add the ability
to send attachments via the nullmailer-inject call.  I could not find
much documentation on google about nullmailer.  Has anyone used it
before to send attachments?   Here is function  I have so far that
sends a regular email.  The variables like recipient are set from a cgi
in another part of the script.

 thanks

 Ty

def genmail(reql):
  if nosend: return
  recip=recipient
  cap=form.keys()
  cap.sort()
  mailfl=os.popen('/usr/bin/nullmailer-inject -f '+fromaddr,'w')
  mailfl.write('To: '+recipient+nl)
  if fromaddr: mailfl.write('From: '+fromaddr+nl)
  mailfl.write('Subject: %s%s\n\n'%(subject,uri))
  mailfl.write(intro)
  rx=0
  prev=''
  for x in cap:
while (rxprev:
putln(reql[rx],mailfl)
  rx=rx+1
putln(x,mailfl)
prev=x

  for x in envl:
mailfl.write('%s: %s\n'%(x,env[x]))
  mailfl.close()

-- 
http://mail.python.org/mailman/listinfo/python-list