[Zope] sendmail with dtml-var
Joshua Newman
josh@jnew.org
01 Jun 2002 11:36:39 -0500
Finally, success!!
After only 3 days of working on this...
Here is the code to build the variable 'mail_group' in a form of
checkboxes for indicating the recipients of the mail. ('Residents' is a
folder containg: several of the ZClass 'Resident' with properties
first_name, last_name, and email_address et. al.; all strings).
<form action="SendFeedback" method="post">
<dtml-in "Residents.objectValues('Resident')" sort=last_name >
<INPUT TYPE="checkbox" NAME="mail_group:list" value=""<dtml-var
first_name> <dtml-var last_name>" <<dtml-var email_address>>">
<dtml-var first_name>
<dtml-var last_name>
<dtml-var email_address><br>
</dtml-in>
Type your comments here <br>
<textarea name="comments" rows="10" cols="50">
</textarea><br>
<input type="submit" value="Send Feedback">
</form>
(you need the ':list' in NAME="mail_group:list" to convert the case of
only a single checked box from a string to a list)
" is "
< is <
> is >
This makes a mail_group variable ['"first last"
<name@where.com>','"first2 last2" <name2@here.com>"',...]
Then the dtml send method 'SendFeedback' is:
<dtml-let addr="_.string.join(mail_group,', ')">
<dtml-sendmail mailhost="MailHost">
To: <dtml-var addr>
Subject: whatever
From: whoever@wherever.com
Comments:<dtml-var comments>
</dtml-sendmail>
</dtml-let>
This works only because <dtml-var addr> within sendmail renders things
perfectly:
"first last" <name@where.com>,...
But outside the sendmail tags
<dtml-var addr> renders as:
first last, first2 last2,...
unless I put <dtml-var html_quote> when it renders as
"first last" <name@where.com>,...
But strangely when I write:
To:<dtml-var html_quote> in the sendmail form, I get that
bizarre error message from my previous posting:
{'"': (550, '5.1.1 <">... User unknown')} '
So I would love to know why this works. Simply being enclosed in
<dtml-sendmail> shouldn't allow <dtml-var> to render html characters but
it does, and I'm glad it does.
I couldn't find any documentation on <dtml-sendmail> and I don't
understand the stuff under the hood from python-->zope-->html-->sendmail-->
So I'll just use it and won't anger the gods...
But if anyone can tell me why, I would love to know.
The take home lesson is:
REMEMBER The HTML Coded Character Set at
http://www.w3.org/MarkUp/html-spec/html-spec_13.html (and elsewhere)
if you want to format things in the middle of html. It seems the only
way to mix dtml syntax with html.
Thanks again for the help Dirk. You had the right idea. Execution
was just much trickier than I had expected.
Also thanks to Amos with his sendmail mailform how-to:
http://www.zope.org/Documentation/How-To/MailForm
joshua
Zope can be like a skittish lover,
sometimes it can be so withholding,
but if you say the right things,
it really puts out.