Please Help:[JavaMail]How to make the embeded images display properly when to show a Multipart/relat

Discussion in 'Java' started by M.Liang Liu, May 25, 2007.

  1. M.Liang Liu

    M.Liang Liu Guest

    Hi,all:
    I am writing a web application to show mails received by JavaMail.
    And I found that some content-type of the mail headers is:multipart/
    related,which means there are some embeded images,vidios,etc.And I
    checked the original tmp file to find the mail contains one part
    labeled "text/html",including tokens as this:
    ++++++++++++++++++++++++++++++++++++++
    <DIV><FONT face=Verdana><IMG alt="" hspace=0
    src="cid:"
    align=baseline border=0></DIV>
    ++++++++++++++++++++++++++++++++++++++
    I found the id of one of the parts which looks like an attachment, is
    "" and I assumed that it was the very image.
    OK,the question is:
    How to make the embeded images display properly when to show a HTML
    message?

    Any comments is greatly appreciated.
    Pardon me for my poor English :)
    M.Liang Liu, May 25, 2007
    #1
    1. Advertising

  2. M.Liang Liu

    M.Liang Liu Guest

    On May 25, 6:16 pm, "M.Liang Liu" <> wrote:
    > Hi,all:
    > I am writing a web application to show mails received by JavaMail.
    > And I found that some content-type of the mail headers is:multipart/
    > related,which means there are some embeded images,vidios,etc.And I
    > checked the original tmp file to find the mail contains one part
    > labeled "text/html",including tokens as this:
    > ++++++++++++++++++++++++++++++++++++++
    > <DIV><FONT face=Verdana><IMG alt="" hspace=0
    > src="cid:"
    > align=baseline border=0></DIV>
    > ++++++++++++++++++++++++++++++++++++++
    > I found the id of one of the parts which looks like an attachment, is
    > "" and I assumed that it was the very image.
    > OK,the question is:
    > How to make the embeded images display properly when to show a HTML
    > message?
    >
    > Any comments is greatly appreciated.
    > Pardon me for my poor English :)


    Multipart mp = (Multipart) part.getContent();
    Part tmp = mp.getBodyPart(0);
    String body = LmlMessage.getBody(tmp, userName);
    int count = mp.getCount();
    for (int k = 1; k < count; k++) {
    Part att = mp.getBodyPart(k);
    String attname = att.getFileName();
    File attFile = new File(Constants.tomcat_AttHome_Key,
    userName.concat(attname));
    FileOutputStream fileoutput = new FileOutputStream(
    attFile);

    try {
    InputStream is = att.getInputStream();
    BufferedOutputStream outs = new BufferedOutputStream(
    fileoutput);
    byte b[] = new byte[att.getSize()];
    is.read(b);
    outs.write(b);
    outs.close();
    } catch (Exception e) {
    logger
    .error("Error occurred when to get the photos from server");
    }
    String Content_ID[] = att.getHeader("Content-ID");
    if (Content_ID != null && Content_ID.length > 0) {
    String cid_name = Content_ID[0].replaceAll("<", "")
    .replaceAll(">", "");
    body = body.replaceAll("cid:" + cid_name,
    Constants.server_attHome_Key.concat("/")
    .concat(userName.concat(attname)));
    }
    }
    sb.append(body);
    return sb.toString();
    M.Liang Liu, May 28, 2007
    #2
    1. Advertising

  3. M.Liang Liu

    Roedy Green Guest

    On 25 May 2007 03:16:17 -0700, "M.Liang Liu" <>
    wrote, quoted or indirectly quoted someone who said :

    >How to make the embeded images display properly when to show a HTML
    >message?


    I think what you have to do is translate the bastardised HTML used in
    Emails into traditional HTML, then render that.

    See http://mindprod.com/jgloss/htmlrendering.html
    --

    Roedy Green Canadian Mind Products
    The Java Glossary
    http://mindprod.com
    Roedy Green, May 28, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Tajonis
    Replies:
    4
    Views:
    4,587
    Tajonis
    Feb 23, 2006
  2. Barrett
    Replies:
    1
    Views:
    283
    Gabriel Genellina
    Apr 23, 2010
  3. Replies:
    8
    Views:
    2,770
  4. bigsea76
    Replies:
    0
    Views:
    126
    bigsea76
    Apr 17, 2004
  5. Replies:
    1
    Views:
    399
Loading...

Share This Page