[Zope] Conditional dtml-boundary in dtml-sendmail

Josef Meile jmeile at hotmail.com
Wed Apr 9 16:40:01 EDT 2008

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

<dtml-let email="REQUEST.get('aba_email_txt').encode('utf-8')"

<dtml-sendmail smtphost="my_host.my_domain.com">
To: my_mail at 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">
    Some html code comes here
<dtml-boundary type="application/octet-stream" disposition="attachment"
><dtml-var "file1.read()"><dtml-boundary type="application/octet-stream"
><dtml-var "file2.read()"><dtml-boundary type="application/octet-stream"
><dtml-var "file3.read()"></dtml-mime>

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"
><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

More information about the Zope mailing list