multiplart/related + multipart/alternative

119 views
Skip to first unread message

Ben Walton

unread,
May 9, 2011, 4:13:18 PM5/9/11
to mail...@googlegroups.com
Hi All,

I'm at a bit of a loss here. I need to generate a mail that has:

text part
html part

The html part needs to reference two other image parts by cid.

That's no problem, but I get a mail that is multipart/altnerative with
four parts
text
html
img1
img2

This displays fine in many clients and works as expected. In
thunderbird and various mac mail versions, it doesn't work correctly
as they're interpretting the standard more correctly (I think). They
basically do: Hey, img2 is something I can display and it's the
highest quality alternative so I'll show it and nothing else.

What I need to generate is something like:
http://people.dsv.su.se/~jpalme/ietf/mhtml-test/mhtml-12.txt

It's "multipart/related; multipart/alternative" which allows providing
the text/plain fallback and an html part that references attached
images.

Is this doable with ruby mail? I'm not seeing how I can accomplish
this. Help is greatly appreciated.

Thanks
-Ben
--
---------------------------------------------------------------------------------------------------------------------------
Ben Walton <bdwa...@gmail.com>

The impact of human uniqueness upon the world
has been enormous because it has established  a new kind of evolution
to support the transmission across generations of learned knowledge
and behaviour."
-Stephen Jay Gould
---------------------------------------------------------------------------------------------------------------------------

Ben Walton

unread,
May 10, 2011, 12:05:04 PM5/10/11
to mail...@googlegroups.com
> What I need to generate is something like:
> http://people.dsv.su.se/~jpalme/ietf/mhtml-test/mhtml-12.txt
>
> It's "multipart/related; multipart/alternative" which allows providing
> the text/plain fallback and an html part that references attached
> images.

I'm not sure if this is the best method or not, but I've solved this by doing:

1. generate a mail with text/plain and text/html parts, content type
multipart/alternative
2. generate a second mail where i add the encoded body of the first,
attach the referenced files and forcibly set the content type.

Seems to work...

Dave Ungerer

unread,
Nov 9, 2011, 7:34:48 AM11/9/11
to mail...@googlegroups.com
Since no-one else has provided sample code and I wasted hours getting this to work, here's how I did it, for future reference:


Some of the instructions here mention explicitly setting the content-type to "multipart/alternative".  But that's a mistake, because then you overwrite the boundary specification.  Just copy it over as in my example, or pull your hair out for hours.

I really really think this should be in the README until it's fixed.

Regards,
Dave Ungerer
Reply all
Reply to author
Forward
0 new messages