I am running into a strange problem with Zope MailTemplates; it probably reflects my rather shallow understanding of Zope in general.

I am using a Python Script as my index_html. It has a simple form and calls itself on submit.


And I use another Python Script that simply calls my MailTemplate object:

--index_html--

request = container.REQUEST
RESPONSE =  request.RESPONSE

if not request.has_key('next_state'):
   return container['index.zpt'](context, request)

if request['next_state']=="Client Lookup":
  error=''
  message=''
  try:
    container.send_template()
    message = "Mail Sent!"
  except:
    error = "Error sending Mail!"

  return container['index.zpt'](context, request, error=error, message=message)

--/index_html--

--send_template--
msg =  container.test_mt.as_message(
    mfrom='[EMAIL PROTECTED]'.encode('utf-8'),
    mto='[EMAIL PROTECTED]'.encode('utf-8'),
    subject='This is the Subject of a MailTemplate'.encode('utf-8'),
    message='This is the body'.encode('utf-8'),
    encoding='utf-8'
    )
msg.send()
return 'Mail Sent'
--/send_template--

My mailtemplate is the same on that is used in the examples(with a small typo corrected (s/option/options):

--test_mt--
      <tal:body xmlns:tal="http://xml.zope.org/namespaces/tal";
          xmlns:metal="http://xml.zope.org/namespaces/metal";
      >Dear <tal:x replace="options/mto"/>,

      <tal:x replace="user/getId"/> would like to thank you for
      your interest in:
      <a href=""
         tal:define="url root/absolute_url"
         tal:attributes="href url"
         tal:content="url"/>

      <tal:x replace="options/message"/>

      cheers,

      The Web Team
      </tal:body>

--/test_mt--

the send_template script works when tested from the ZMI.

When the MailTemplate was first created, it defaulted to text/plain. The weird thing is that this effected my main zpt in addition to the email. So after submitting the form, the zpt came back rendered as code instead of html, until I clued into what was happening and changed the MailTmeplate to text/html.

Is there a really good reason for this behaviour that I am missing?
_______________________________________________
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 )

Reply via email to