[Zope] Re: MailTemplate multipart/alternative samples

Chris Withers chris at simplistix.co.uk
Mon May 14 19:51:43 EDT 2007


(CC'ing in the relevent mailing lists so that this gets archived there)

Giovanni Coi wrote:
> After installing your MailTemplates product (working well with the
> code from the readme.txt example section ) I need
> some help.

Glad they worked well so far :-)

> May I have some hints/sample how to use MailTemplates for
> obtain a multipart/alternative message?
> 
> For example the first part plain/text e and the second one
> text/html and no file attachment.

Sure, what I'd do is use the template to generate the html and render 
that to a message:

  msg = container.my_html_mail.as_message(
             mfrom='from at example.com',
             mto='to1 at example.com',
             subject='Your requested file',
             )

Then I'd add a Mimetext object with the plain text version:

from email.mime.text import MIMEText
msg.attach(MIMEText(text_version_of_your_message))

And finally send the message:

msg.send()

Of course, the "fun" bit is generating the plain text version of the 
message from the html version.

You might try stripogram for that:

http://sourceforge.net/project/showfiles.php?group_id=1083&package_id=34645

...but your milleage may vary (a lot!)

cheers,

Chris

-- 
Simplistix - Content Management, Zope & Python Consulting
            - http://www.simplistix.co.uk


More information about the Zope mailing list