By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,719 Members | 1,875 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,719 IT Pros & Developers. It's quick & easy.

Java Mail API sending HTML email won't display images from cid

P: 7
My collegue and I are at the point of pulling our hair out. I'm currently writting a little piece of Java code to send an email confirmation page that sends both html and text. Not a problem. In my html, I'm using an image with which I reference through a cid i1. My problem is, in the email I send, I can only get the images to show up if I do:

Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">
  2. <head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /><title>E-Announcement</title></head>
  3. <body>
  4. <img src="cid:i1">
  5. </body></html>
  6.  
If I try to use any sort of inline css like this

Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">
  2. <head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /><title>E-Announcement</title></head>
  3. <body>
  4. <div style="background-image:url(cid:i1); background-repeat: no-repeat; width: 670px; height: 338px; position: relative; margin-left: auto; margin-right: auto; z-index: 1;">Some text</div>
  5. </body></html>
  6.  
or use a table with css

Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">
  2. <head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /><title>E-Announcement</title></head>
  3. <body>
  4. <table width="500" height="500">
  5. <tr valign=3D"top"><td style=3D"background-image:url(cid:i1)">This is a test</td>
  6. </tr>
  7. </table>
  8. </body></html>
  9.  
I can't get the images to EVER show up.
My Java code to attach the images is taken straight from
this example from SUN:
http://java.sun.com/developer/online...geExample.java
Since the IMG tag shows the image just fine, I do not believe the JAVA code is the problem. Please note that I am testing this with Thunderbird, but I have tried using gmail and hotmail and am seeing the same results.
Is there some trick to get images to show up using the Java code with tags other than <IMG> that I don't know about?
Thanks in advance for any expert advice.
Dec 5 '06 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.