[Zope] How to create a file and send it by e-mail ?
Chris Withers
chris at simplistix.co.uk
Tue Oct 11 06:56:40 EDT 2005
(please keep the list CC'ed in)
Nicolas Georgakopoulos wrote:
> Chris Withers wrote:
>
>> Nicolas Georgakopoulos wrote:
>>
>>> Hello all, I'm developing using ZPT and I need to create a file (CSV
>>> format) but I'm having some problems:
>>>
>>> * 1. *I only know how to create files with python but I get an
>>> * Error Type: NameError*
>>> * Error Value: global name 'file' is not defined.
>>
>> Indeed, just build your csv as a string :-)
>
>
> Yes I will build my csv as string but how can I save it as a file ?
Why do you think you need to?
Is the csv data dynamically generated?
If you need to store it, create a Zope File Object in the python script
that processes submission from your ZPT.
>>> * 2.*When I create my file how can I send it as an attachment by mail
>>> ? (I already have setup my mail host object and I can send mail's
>>> successfully.)
>>
>> I just wrote a product specifically for this ;-)
>>
>> http://www.simplistix.co.uk/software/zope/mailtemplates
>>
> Thanks, I'm looking to it rigth now.
You'll want to build your own MIMEBase object and attach it to the
result of rendering your Mail Template if you build your csv in a string.
If you end up with a Zope File object or a ZPublisher FileUpload object,
then you can just do:
msg = context.my_mail_template.as_message(
# insert your params here
)
msg.add_file(your_file)
There's plenty of examples in the readme.txt file, or in the tests folder...
cheers,
Chris
--
Simplistix - Content Management, Zope & Python Consulting
- http://www.simplistix.co.uk
More information about the Zope
mailing list