[Zope] How to create a file and send it by e-mail ?

2005-10-11 Thread Nicolas Georgakopoulos
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.

* I think ZOPE doe's not allow python to create files for security 
reasons. Can I change this security policy or it will make my 
application unsafe? Is there another way to create a file using ZOPE API 
calls ?


* 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.)


thanks for your time..

*

*
___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
http://mail.zope.org/mailman/listinfo/zope-announce

http://mail.zope.org/mailman/listinfo/zope-dev )


Re: [Zope] How to create a file and send it by e-mail ?

2005-10-11 Thread Chris Withers

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 :-)

* 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

cheers,

Chris

--
Simplistix - Content Management, Zope  Python Consulting
   - http://www.simplistix.co.uk
___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
http://mail.zope.org/mailman/listinfo/zope-announce

http://mail.zope.org/mailman/listinfo/zope-dev )


Re: [Zope] How to create a file and send it by e-mail ?

2005-10-11 Thread Tino Wildenhain

Nicolas Georgakopoulos schrieb:
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.


While I wonder how do you create a file in python using file?

* I think ZOPE doe's not allow python to create files for security 
reasons. Can I change this security policy or it will make my 
application unsafe? Is there another way to create a file using ZOPE API 
calls ?


You dont need a real (filesystem-) file if all you want is sending it
over the net. Usually you just build a string - for example in python
scripts via print/return printed or as a list which you join.

* 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.)


This is a bit more difficult, there are examples to send mails
with attachments per DTML, but if you want to avoid you either
open the python email package for python scripts or use
ChrisWs product (but I did not have the time to test it - so
try it :-)

Regards
Tino
___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
http://mail.zope.org/mailman/listinfo/zope-announce

http://mail.zope.org/mailman/listinfo/zope-dev )


Re: [Zope] How to create a file and send it by e-mail ?

2005-10-11 Thread Chris Withers

(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
___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
http://mail.zope.org/mailman/listinfo/zope-announce

http://mail.zope.org/mailman/listinfo/zope-dev )