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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • shaolinman829
    New Member
    • Nov 2006
    • 7

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

    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:

    Code:
    <!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">
    <head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /><title>E-Announcement</title></head>
    <body>
    <img src="cid:i1">
    </body></html>
    If I try to use any sort of inline css like this

    Code:
    <!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">
    <head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /><title>E-Announcement</title></head>
    <body>
    <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>
    </body></html>
    or use a table with css

    Code:
    <!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">
    <head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /><title>E-Announcement</title></head>
    <body>
    <table width="500" height="500">
    <tr valign=3D"top"><td style=3D"background-image:url(cid:i1)">This is a test</td>
    </tr>
    </table>
    </body></html>
    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:

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