create HTML mail with inline image using MIMETools
Hi, I need to create a HTML mail (yes, I kow ...) with an embedded image within Zope and send it using sendmail. To be able to set the Content-ID, I use version 1.12 of the MIMITools (http://cvs.zope.org/Products/MIMETools/MIMETag.py) However I get stuck because I can not set the boundary string within the <dtml-mime> tag. A random boundary is generated by the <dtml-boundary> tag but I need to know the boundary string to set it in the mail header. What I did: <dtml-sendmail mailhost="MailHost"> From: foo@bar.xy To: foo@bar.xy Date: Mon, 22 Mar 2004 16:25:03 +0100 Subject: html with image MIME-Version: 1.0 Content-Type: multipart/related; boundary="----=_NextPart_000_1.0000" This is a multi-part message in MIME format. ------=_NextPart_000_1.0000 Content-Type: multipart/alternative; boundary="----=_NextPart_000_2.0000" ------=_NextPart_000_2.0000 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD><TITLE></TITLE></HEAD> <BODY> <P>Hello World</P> <br> <IMG src=3D"cid:123@456"> </BODY> </HTML> ------=_NextPart_000_2.0000-- <dtml-mime> <dtml-boundary type="image/gif" filename="my_image.gif" encode="base64" cid="123@456" > <dtml-var "test_gif"> </dtml-mime> ------=_NextPart_000_1.0000-- Has anyone succesfully created HTML mails with embedded images using <dtml-mime>? Regards Christoph
Christoph Landwehr wrote at 2004-3-22 18:07 +0100:
I need to create a HTML mail (yes, I kow ...) with an embedded image within Zope and send it using sendmail. To be able to set the Content-ID, I use version 1.12 of the MIMITools (http://cvs.zope.org/Products/MIMETools/MIMETag.py)
However I get stuck because I can not set the boundary string within the <dtml-mime> tag. A random boundary is generated by the <dtml-boundary> tag but I need to know the boundary string to set it in the mail header.
The "dtml-mime" is supposed to set the "boundary" itself. It might be necessary to enhance this tag a bit in order to generate a "multipart/related" rather than a "multipart/mixed" "Content-Type". As an alternative, you can use Pythons "email" package (part of Pythons standard library from Python 2.2 on, can be used for Python 2.1.3 as well) to construct the message and then send it via the "MailHost"'s "send" method. You will need an External Method for this (or allow import and use of the Email package for Python Scripts --> Zope Developer Guide). -- Dieter
Dieter Maurer schrieb:
The "dtml-mime" is supposed to set the "boundary" itself. It might be necessary to enhance this tag a bit in order to generate a "multipart/related" rather than a "multipart/mixed" "Content-Type".
As an alternative, you can use Pythons "email" package (part of Pythons standard library from Python 2.2 on, can be used for Python 2.1.3 as well) to construct the message and then send it via the "MailHost"'s "send" method. You will need an External Method for this (or allow import and use of the Email package for Python Scripts --> Zope Developer Guide).
Thanx for the hint. I was already looking at the email package to work arrond the lackings of dtml-mime. I just got suspicious because I found this in the MIMETools change-log: 1.11: "Added cid and cid_expr fields for the Content-ID header. This is needed for embedding images in a HTML message." Regards Christoph
participants (2)
-
Christoph Landwehr -
Dieter Maurer