Re: [Zope3-Users] Re: Render ZPT template to send rich-text HTML mail

2006-06-01 Thread Alek Kowalczyk




Philipp von Weitershausen wrote:

  [EMAIL PROTECTED] wrote:
  
  
Hi, I need to send some rich-text (HTML) mail, containing information
based on many objects. It would be nice to render it using ZPT
provided by Zope instead of manual creation of HTML text.

Can I (ab)use ZPT for such purpose? I need to design ZPT template and
write corresponding View object. How to wire together the ZPT
template and corresponding View object to render a HTML message and
send it using mail utility?

  
  
Let's say that the 'mail.html' view provides the HTML for the email body
(whether that's ZPT, Python, or whatever doesn't matter), then you can
simply do:

  >>> from zope.component import getMultiAdapter
  >>> view = getMultiAdapter((obj, request), name="@@mail.html")
  >>> html_email_body = view()
  

Wow, ingenious in its simplicity! This is what I wanted :)  

  
Could you suggest some points to start with?

  
  Buy my book?

Philipp
  

If you present such tricks there - then it's worth to be bought...

Best Regards!
Alek.


___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


[Zope3-Users] Re: Render ZPT template to send rich-text HTML mail

2006-06-01 Thread Philipp von Weitershausen
Philipp von Weitershausen wrote:
> [EMAIL PROTECTED] wrote:
>> Hi, I need to send some rich-text (HTML) mail, containing information
>> based on many objects. It would be nice to render it using ZPT
>> provided by Zope instead of manual creation of HTML text.
>>
>> Can I (ab)use ZPT for such purpose? I need to design ZPT template and
>> write corresponding View object. How to wire together the ZPT
>> template and corresponding View object to render a HTML message and
>> send it using mail utility?
> 
> Let's say that the 'mail.html' view provides the HTML for the email body
> (whether that's ZPT, Python, or whatever doesn't matter), then you can
> simply do:
> 
>   >>> from zope.component import getMultiAdapter
>   >>> view = getMultiAdapter((obj, request), name="@@mail.html")

W/o the @@ of course

>   >>> html_email_body = view()
> 
>   >>> from email.MIMEText import MIMEText
>   >>> message = MIMETExt(html_email_body.encode('utf-8'),
>   ...'text/html', 'utf-8')
>   >>> # etc.
> 
>   >>> from zope.component import getUtility
>   >>> mailer = getUtility(IMailDelivery, 'your-delivery-utility')
>   >>> mailer.send(from, to, message.as_string())
> 
>> Could you suggest some points to start with?
> 
> Buy my book?
> 
> Philipp

___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


[Zope3-Users] Re: Render ZPT template to send rich-text HTML mail

2006-06-01 Thread Philipp von Weitershausen
[EMAIL PROTECTED] wrote:
> Hi, I need to send some rich-text (HTML) mail, containing information
> based on many objects. It would be nice to render it using ZPT
> provided by Zope instead of manual creation of HTML text.
> 
> Can I (ab)use ZPT for such purpose? I need to design ZPT template and
> write corresponding View object. How to wire together the ZPT
> template and corresponding View object to render a HTML message and
> send it using mail utility?

Let's say that the 'mail.html' view provides the HTML for the email body
(whether that's ZPT, Python, or whatever doesn't matter), then you can
simply do:

  >>> from zope.component import getMultiAdapter
  >>> view = getMultiAdapter((obj, request), name="@@mail.html")
  >>> html_email_body = view()

  >>> from email.MIMEText import MIMEText
  >>> message = MIMETExt(html_email_body.encode('utf-8'),
  ...'text/html', 'utf-8')
  >>> # etc.

  >>> from zope.component import getUtility
  >>> mailer = getUtility(IMailDelivery, 'your-delivery-utility')
  >>> mailer.send(from, to, message.as_string())

> Could you suggest some points to start with?

Buy my book?

Philipp

___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users