Re: [Zope] How to create a file and send it by e-mail ?
(yet again, please CC zope@zope.org in replies..) Nicolas Georgakopoulos wrote:
I think I need it...
I don't ;-)
I have made a web page (ZPT) that a user answer's to a questionnaire , most of the answers are provided by check boxes and radio buttons. When the user submit the answers a mail is send with the answers by text in a string format like coma separated values.
You have a python script to do this, right?
The problem is that my client request to get the answer by mail with a file as an attachment so he can analyze the data with a statistical program SPSS. Can this be done with Zope File Object ? (I don't think it can... )
You don't need a file object. Build the thing you want to send as a string called data, and have a string variable called filename containing the name you want to use for the attachment. Then you need create a MIMEBase object for it: # some imports from email.MIMEBase import MIMEBase from email import Encoders # now create the attachment msg = MIMEBase(maintype, subtype) msg.set_payload(data) Encoders.encode_base64(msg) msg.add_header('Content-Disposition', 'attachment', filename=filename) # now render the MailTemplate wrapper = context.my_mail_template.as_message( # insert params here ) # finally, attach the file and send wrapper.attach(msg) wrapper.send() You may also be interested in something I will likely add for the 1.1.0 release: https://secure.simplistix.co.uk/support/issue180 cheers, Chris -- Simplistix - Content Management, Zope & Python Consulting - http://www.simplistix.co.uk
participants (1)
-
Chris Withers