Skip to content


Subversion checkout URL

You can clone with
Download ZIP


Fix email composing for attaches #1403

wants to merge 1 commit into from

4 participants



Current implementation of e-mail composing put all of the mail parts into one multipart/related part. As result Ms Outlook (and possible some other mail clients) doesn't show attachment.

The idea of this fix is put all inline attachments into multipart/related part and, the other ones are placed in multipart/mixed part (togeher with multipart/related part). I've tested both images and attachments (I used pdf) with Outlook 2010 - all works for me.



This changes the behavior. The current behavior is necessary if you want to include images in an HTML message.

I'm all for new additional behavior, but silently changing behavior is not good.


Maybe I described it ambiguously, but actually it doesn't change current behavior. The images are still placed in multipart/related message part, so inline images are located properly (at least in Outlook).

So, in case if both attachments and inline images are available the MIME structure will be:
multipart/mixed start
multipart/related start
multipart/related end
multipart/mixed end


BTW, I've checked gmail web interface as a reference implementation. It's works the same way (with exception, that it also added multipart/alternative mime part to add plain text body).


I wonder if something like or could help.


So, this pull request has been open for 4 months, and there's been no movement on it. Seeing as there appears to be some dispute over whether or not this implementation is desired, perhaps this PR should be closed until such a time as an agreement is reached?


It would be nice if someone have problems described in the…#/activity/ticket: test the patch.
As for me, we are just have class derived from Mailer with this patch in our project. Now it's in production for several months, and there are no issues (at least we don't know about it).


Ok, this is over a year old at this point. I'm going to take this over and see if I can't make heads or tails of whether or not it works or breaks anything and open my own PR. If sending attachments is broken for some Outlooks that's something we should try to un-break in 2.6 if possible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
@@ -100,4 +100,10 @@ a.rashid at zantekk dot com
Kristof Jozsa
### Email: ###
-kristof.jozsa at gmail dot com
+kristof.jozsa at gmail dot com
+### Name: ###
+Mikhail Limansky
+### Email: ###
+mike.limansky at gmail dot com
49 core/util/src/main/scala/net/liftweb/util/Mailer.scala
@@ -288,30 +288,45 @@ trait Mailer extends SimpleInjector {
case XHTMLPlusImages(html, img@_*) =>
val html_mp = new MimeMultipart("related")
val bp2 = new MimeBodyPart
+ val (attachs, images) = img.partition(_.attachment)
bp2.setContent(encodeHtmlBodyPart(html), "text/html; charset=" + charSet)
- img.foreach {
- i =>
- val rel_bpi = new MimeBodyPart
- rel_bpi.setFileName(
- rel_bpi.setContentID(
- rel_bpi.setDisposition(if (!i.attachment) "inline" else "attachment")
- rel_bpi.setDataHandler(new javax.activation.DataHandler(new javax.activation.DataSource {
- def getContentType = i.mimeType
- def getInputStream = new
- def getName =
- def getOutputStream = throw new"Unable to write to item")
- }))
- html_mp.addBodyPart(rel_bpi)
+ images.foreach {
+ i => html_mp.addBodyPart(buildAttachment(i))
+ }
+ if (attachs.isEmpty) {
+ bp.setContent(html_mp)
+ } else {
+ val mixed_mp = new MimeMultipart("mixed")
+ val html_p = new MimeBodyPart
+ html_p.setContent(html_mp)
+ mixed_mp.addBodyPart(html_p)
+ attachs.foreach {
+ i => mixed_mp.addBodyPart(buildAttachment(i))
+ }
+ bp.setContent(mixed_mp)
- bp.setContent(html_mp)
+ private def buildAttachment(holder: PlusImageHolder) = {
+ val part = new MimeBodyPart
+ part.setFileName(
+ part.setContentID(
+ part.setDisposition(if (holder.attachment) Part.ATTACHMENT else Part.INLINE)
+ part.setDataHandler(new javax.activation.DataHandler(new javax.activation.DataSource {
+ def getContentType = holder.mimeType
+ def getInputStream = new
+ def getName =
+ def getOutputStream = throw new"Unable to write to item")
+ }))
+ part
+ }
* Asynchronously send an email.
Something went wrong with that request. Please try again.