Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Fix email composing for attaches #1403

Closed
wants to merge 1 commit into from

4 participants

Mike Limansky David Pollak nafg Matt Farmer
Mike Limansky

Hi!

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.

David Pollak
Owner

-1

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.

Mike Limansky

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
text/html
image
image...
multipart/related end
attachment
multipart/mixed end

Mike Limansky

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).

nafg

I wonder if something like http://litmus.com/ or http://www.campaignmonitor.com/testing/ could help.

Matt Farmer
Collaborator

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?

Mike Limansky

It would be nice if someone have problems described in the https://www.assembla.com/spaces/liftweb/tickets/1197-improve-mailer-functionality-for-attachments…#/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).

Matt Farmer
Collaborator

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.
8 contributors.md
View
@@ -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
View
@@ -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)
html_mp.addBodyPart(bp2)
- img.foreach {
- i =>
- val rel_bpi = new MimeBodyPart
- rel_bpi.setFileName(i.name)
- rel_bpi.setContentID(i.name)
- 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 java.io.ByteArrayInputStream(i.bytes)
-
- def getName = i.name
-
- def getOutputStream = throw new java.io.IOException("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)
}
bp
}
+ private def buildAttachment(holder: PlusImageHolder) = {
+ val part = new MimeBodyPart
+ part.setFileName(holder.name)
+ part.setContentID(holder.name)
+ 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 java.io.ByteArrayInputStream(holder.bytes)
+
+ def getName = holder.name
+
+ def getOutputStream = throw new java.io.IOException("Unable to write to item")
+ }))
+ part
+ }
+
/**
* Asynchronously send an email.
Something went wrong with that request. Please try again.