cfmail html email with "cid" embedded images doesn't work right

656 views
Skip to first unread message

Bruce Kirkpatrick

unread,
Jul 9, 2014, 12:50:25 PM7/9/14
to ra...@googlegroups.com
I just discovered that my code for embedding images that I had working on coldfusion 9, doesn't work on Railo.  First time I've tested it in almost 3 years.

When I compare the email headers with the output of phpmailer, I find it isn't possible to mimic the output phpmailer generates using railo cfmail.   I don't know what coldfusion output is and whether it works in coldfusion or not, but it would be nice if this worked in railo.

If someone has code for this that works in the Thunderbird email client let me know.    Many other clients will accept the cfmail headers for cid embedded images, but Thunderbird expects a more strict RFC compliance that I don't know how to generate with CFMAIL.  I can generate the correct syntax with phpmailer though.

I've actually tried a lot of variations of the code, but I think the most correct methods are listed below.

The correct raw email header output that thunderbird understand is supposed to be this:

...removed other headers for brevity...
Content-Type: multipart/related;
boundary="b1_39a4ced68062ba31f7d21e28eb7f8e72"

--b1_39a4ced68062ba31f7d21e28eb7f8e72
Content-Type: text/html; charset=us-ascii

Hello, <b>my friend</b> <img src="cid:logo" width="20" height="20">!


--b1_39a4ced68062ba31f7d21e28eb7f8e72
Content-Type: image/jpeg; name="slide1.jpg"
Content-Transfer-Encoding: base64
Content-ID: <logo>
Content-Disposition: inline; filename=slide1.jpg

/9j/4QAYRXhpZgAASUkqAAgAAAAAAAAAAAAAAP/sABFEdWNreQABAAQAAABQ
lots more base64....


But Railo generates an email like this that is blank when opened in thunderbird:
Content-Type: multipart/related
X-Mailer: Railo Mail
X-SG-EID: UzvFFkX/YNBKOFeeClTgeL+UnUBTPNXMDPzrdkNsUDz5KVf+Bes3R3yf4OH16LwVSrhm4sp5GHTsqZAn0CUm7+7DiieWOKWREqQMwJmCJTErl/7PIun3iTcUhb6dXsAn2OQ6cdj48LQx4/pGB4I4lm8A1nvzU/R1baYMpi37yGs=
Sender: emailremoved

This is a multi-part message in MIME format...

----
with this code:
<cfmail to="emailremoved" from="emailremoved" subject="email with image" charset="utf-8" type="html">
<cfmailparam name="Content-Type" value="multipart/related"> 
<cfmailparam file="slide1.jpg" contentid="<logo>" disposition="inline" />
<cfmailpart type="text/html"> Hello, <b>my friend</b> <img src="cid:logo" width="20" height="20">!
</cfmailpart>

  </cfmail>
and the same with this code:
<cfmail to="someone" from="someone" subject="email with image" charset="utf-8" type="html"> 
<cfmailparam name="Content-Type" value="multipart/related"> 
Hello, <b>my friend</b> <img src="cid:logo" width="20" height="20">!
<cfmailparam file="slide1.jpg" contentid="<logo>" disposition="inline" /> 
  </cfmail>

With this code I get an email with the image as an attachment instead of being inline in the html.:
<cfmail to="emailremoved" from="emailremoved" subject="email with image" charset="utf-8" type="html">
<cfmailparam file="slide1.jpg" contentid="<logo>" disposition="inline" />
<cfmailpart type="text/html"> Hello, <b>my friend</b> <img src="cid:logo" width="20" height="20">!
</cfmailpart>

  </cfmail>


This was supposed to be fixed according to https://issues.jboss.org/browse/RAILO-661 but I don't see that it is and I'm trying to use the same code example in that bug report pretty much.  I'm concerned that a regression has happened or that the fix is still wrong.  

The main difference between phpmailer and the cfmail output is the first "Content-Type".   phpmailer has this header:
Content-Type: multipart/related;
boundary="b1_39a4ced68062ba31f7d21e28eb7f8e72"

but that isn't possible to do with cfmail (Based on my limited knowledge).

I think the multipart/related mime concept is that it tells the mail client that the inline images and the html are "related", so it combines them, instead of displaying them separately.

Any chance we could get a fix that could allow the more strict output that works in thunderbird?

Bruce Kirkpatrick

unread,
Jul 9, 2014, 1:27:47 PM7/9/14
to ra...@googlegroups.com
Sweet, I was able to fix the bug in the Railo Java code.

Line 440: mp = new MimeMultipart();
must be this: mp = new MimeMultipart("related");

This fixed any email with cid inline embedded graphics and it doesn't break an html email without inline graphics.

Michael van Leest

unread,
Jul 9, 2014, 9:04:02 PM7/9/14
to ra...@googlegroups.com
Great! Did you post this as a bug so they can include the fix?

Thanks!


--
Did you find this reply useful? Help the Railo community and add it to the Railo Server wiki at https://github.com/getrailo/railo/wiki
---
You received this message because you are subscribed to the Google Groups "Railo" group.
To view this discussion on the web visit https://groups.google.com/d/msgid/railo/ad0be60d-cd21-46cb-af97-f0dc395a7956%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Michael van Leest

Bruce Kirkpatrick

unread,
Jul 9, 2014, 9:13:17 PM7/9/14
to ra...@googlegroups.com
I actually did a pull request on github for this today and commented on the existing bug.   I also made a custom build of railo for this and the multiple file upload fix so I could start using this immediately.

Bruce Kirkpatrick

unread,
Jul 13, 2014, 1:21:11 PM7/13/14
to ra...@googlegroups.com
I'm hosting the Railo patch that fixes this issue on my open source project web site now since it depends on it:

Ulf Unger

unread,
Jul 14, 2014, 9:02:20 AM7/14/14
to ra...@googlegroups.com
Hello Bruce,

the problem is that multipart/related is the WRONG mimetype - although Adobe uses it - test your mails (if you have combination of inline and "normal" attachments) in iOS Mail app -> you will not find the "normal" attachments to be available.

The only correct way to send these attachments is with "multimart/mixed", and railo did fix that (https://issues.jboss.org/browse/RAILO-2821), the downside of this "official" way, that work in all mail clients is, that they're going to show you the "attachment" icon, although the attachments are just "inline" ones.

So you should try your code with "multipart/mixed" mode, and see if thats working too.

Greetings

Ulf

Bruce Kirkpatrick

unread,
Jul 14, 2014, 10:35:41 AM7/14/14
to ra...@googlegroups.com
Ulf,  thanks for the information, but you must look at the Java code too, since it's not one size fits all for the email headers in CFMAIL - it's determined with logic based on how the email is composed.  I only changed the line that affects emails WITHOUT regular attachments.   So in your test case, you would have nothing to object to since it is still multipart/mixed for inline image + attachment after my change.   multipart/mixed breaks the thunderbird display of the inline images unfortunately when there is a regular attachment, but I don't need attachments with bulk html marketing emails so I can live with that.

It appears that micha may have wiped out the fix in #661 in 3.3 on 4.1.2.005 with jira #2821.  It just needs to be a little more specific like I'm suggesting.
Reply all
Reply to author
Forward
0 new messages