Conditional dtml-boundary in dtml-sendmail
Dear list I'm trying to send a multi-part email after having submitted a form. In that form, the user will give some basic information from him, then he will be able to send at most three files. This is my dtml-method to send email after having submitted the data: <dtml-let email="REQUEST.get('aba_email_txt').encode('utf-8')" name="REQUEST.get('aau_name_txt').encode('utf-8')" lastName="REQUEST.get('aat_vorname_txt').encode('utf-8')" company="REQUEST.get('aas_firma_txt').encode('utf-8')" file1="REQUEST.get('aap_dateien_anhang_dat')" file2="REQUEST.get('aaq_dateien_anhang_dat')" file3="REQUEST.get('aar_dateien_anhang_dat')"> <dtml-sendmail smtphost="my_host.my_domain.com"> To: my_mail@my_domain.com From: &dtml-email; Subject: Anfrage &dtml-name; &dtml-lastName; - &dtml-company; Content-Type: text/html; charset=utf-8 <dtml-mime type="text/html; charset=utf-8"> <html> <body> Some html code comes here </body> </html> <dtml-boundary type="application/octet-stream" disposition="attachment" filename_expr="file1.filename"
<dtml-var "file1.read()"><dtml-boundary type="application/octet-stream" disposition="attachment" filename_expr="file2.filename" <dtml-var "file2.read()"><dtml-boundary type="application/octet-stream" disposition="attachment" filename_expr="file3.filename" <dtml-var "file3.read()"></dtml-mime> </dtml-sendmail> </dtml-let>
Let's say that the user doesn't submit file3, on that case, zope will generate something like this: "some_ramdom_id.dat" and it will attach an empty file. I tried something like this: <dtml-if "file1.filename not in ['', None]"><dtml-boundary type="application/octet-stream" disposition="attachment" filename_expr="file1.filename"
<dtml-var "file1.read()"></dtml-if>
However when I try to save, zope fails and says: """ Error Type: Document Template Parse Error Error Value: Unexpected tag, for tag <dtml-boundary type="application/octet-stream" disposition="attachment" filename_expr="file1.filename" >, on line 215 of sendAnfrage """ The only way I found to cope with this was doing a script to validate if a file has whether a name or not, then I will return a dictionary like this: {'name': real_name_or_dummy_name, 'data': <file.read()>_or_dummy_text} So, I feed the boundary with a dummy file when no file was uploaded. I don't really like to send dummy files since it may confuse the person receiving the emails. Is there any better way of achieving this? Please note that since I'm working in the zmi and I'm not the administrator of the machine where my page is hosted, I can only use dtml to send mail :-(, thus using the python mail library isn't an option on this case. Best regards Josef
The email library should be available to use with a Script (Python) and can be done all within the ZMI. Otherwise maybe use dtml-try? On Wed, Apr 9, 2008 at 4:40 PM, Josef Meile <jmeile@hotmail.com> wrote:
Dear list
I'm trying to send a multi-part email after having submitted a form. In that form, the user will give some basic information from him, then he will be able to send at most three files.
This is my dtml-method to send email after having submitted the data:
<dtml-let email="REQUEST.get('aba_email_txt').encode('utf-8')" name="REQUEST.get('aau_name_txt').encode('utf-8')" lastName="REQUEST.get('aat_vorname_txt').encode('utf-8')" company="REQUEST.get('aas_firma_txt').encode('utf-8')" file1="REQUEST.get('aap_dateien_anhang_dat')" file2="REQUEST.get('aaq_dateien_anhang_dat')" file3="REQUEST.get('aar_dateien_anhang_dat')">
<dtml-sendmail smtphost="my_host.my_domain.com"> To: my_mail@my_domain.com From: &dtml-email; Subject: Anfrage &dtml-name; &dtml-lastName; - &dtml-company; Content-Type: text/html; charset=utf-8 <dtml-mime type="text/html; charset=utf-8"> <html> <body> Some html code comes here </body> </html> <dtml-boundary type="application/octet-stream" disposition="attachment" filename_expr="file1.filename"
<dtml-var "file1.read()"><dtml-boundary type="application/octet-stream" disposition="attachment" filename_expr="file2.filename" <dtml-var "file2.read()"><dtml-boundary type="application/octet-stream" disposition="attachment" filename_expr="file3.filename" <dtml-var "file3.read()"></dtml-mime> </dtml-sendmail> </dtml-let>
Let's say that the user doesn't submit file3, on that case, zope will generate something like this: "some_ramdom_id.dat" and it will attach an empty file. I tried something like this:
<dtml-if "file1.filename not in ['', None]"><dtml-boundary type="application/octet-stream" disposition="attachment" filename_expr="file1.filename"
<dtml-var "file1.read()"></dtml-if>
However when I try to save, zope fails and says:
""" Error Type: Document Template Parse Error Error Value: Unexpected tag, for tag <dtml-boundary type="application/octet-stream" disposition="attachment" filename_expr="file1.filename" >, on line 215 of sendAnfrage """
The only way I found to cope with this was doing a script to validate if a file has whether a name or not, then I will return a dictionary like this: {'name': real_name_or_dummy_name, 'data': <file.read()>_or_dummy_text}
So, I feed the boundary with a dummy file when no file was uploaded. I don't really like to send dummy files since it may confuse the person receiving the emails. Is there any better way of achieving this? Please note that since I'm working in the zmi and I'm not the administrator of the machine where my page is hosted, I can only use dtml to send mail :-(, thus using the python mail library isn't an option on this case.
Best regards Josef
_______________________________________________ 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 )
Tom Von Lahndorff wrote:
The email library should be available to use with a Script (Python) and can be done all within the ZMI.
Yes, I wish it was. I believe that was one of the things I did in the MailTemplates product: just make the standard python email package bits available in Zope protected code. Still, if Josef can't get products installed, he's limited to a world of suck when it comes to email :-( cheers, Chris -- Simplistix - Content Management, Zope & Python Consulting - http://www.simplistix.co.uk
The email library should be available to use with a Script (Python) and can be done all within the ZMI. Otherwise maybe use dtml-try? Well, I should have mentioned this: the zope installed on the server is 2.8.x. Yes, it is old, but it is because all the page uses an own CMS based on silva, which isn't compatible with newer versions.
I tried this: import email and it worked; however, as soon as I tried this: from email.MIMEText import MIMEText msg = MIMEText('Sending mail through python module') or import email msg = email.MIMEText.MIMEText('Sending mail through python module') An Unauthorized exception comes. So, I guess MIMEText is protected at least on 2.8.x. But I guess in 2.11.x is protected as well, or am I wrong? Thanks for your reply. I guess there is no way of achieving what I want on dtml, so, I will try to do it an external method and try to convince people there to store it on the server or I will have to do it on my own server and embebbed it on an iframe or call an external link. Best regards Josef
participants (3)
-
Chris Withers -
Josef Meile -
Tom Von Lahndorff