473,416 Members | 1,674 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,416 software developers and data experts.

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

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 (rx<len(reql) and reql[rx]<x):
if reql[rx]<>prev:
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()

Jul 18 '05 #1
2 2465
On 24 Mar 2005 05:20:06 -0800 tv****@gmail.com 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<len(reql) and reql[rx]<x):
TC> 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]
Jul 18 '05 #2
Thank you Denis

Ty

Jul 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
by: drdoubt | last post by:
using namespace std In my C++ program, even after applying , I need to use the std namespace with the scope resolution operator, like, std::cout, std::vector. This I found a little bit...
9
by: sk | last post by:
I have an applicaton in which I collect data for different parameters for a set of devices. The data are entered into a single table, each set of name, value pairs time-stamped and associated with...
3
by: google | last post by:
I have a database with four table. In one of the tables, I use about five lookup fields to get populate their dropdown list. I have read that lookup fields are really bad and may cause problems...
4
by: Phil | last post by:
k, here is my issue.. I have BLOB data in SQL that needs to be grabbed and made into a TIF file and placed on the client (could be in temp internet dir). The reason we need it in TIF format is...
8
by: Sai Kit Tong | last post by:
In the article, the description for "Modiy DLL That Contains Consumers That Use Managed Code and DLL Exports or Managed Entry Points" suggests the creation of the class ManagedWrapper. If I...
2
by: Michael R. Pierotti | last post by:
Dim reg As New Regex("^\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3}$") Dim m As Match = reg.Match(txtIPAddress.Text) If m.Success Then 'No need to do anything here Else MessageBox.Show("You need to enter a...
5
by: HotRod | last post by:
I am new to this so please go easy. We currently have some students doing some work on some web based tracking documents for us. They are currently using VB .net to develop what we requested....
10
by: L. R. Du Broff | last post by:
I own a small business. Need to track a few hundred pieces of rental equipment that can be in any of a few dozen locations. I'm an old-time C language programmer (UNIX environment). If the only...
15
by: Cheryl Langdon | last post by:
Hello everyone, This is my first attempt at getting help in this manner. Please forgive me if this is an inappropriate request. I suddenly find myself in urgent need of instruction on how to...
23
by: vinod.bhavnani | last post by:
Hello all, I need desperate help Here is the problem: My problem today is with multidimensional arrays. Lets say i have an array A this is a 4 dimensional static array.
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.