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

M

M.Liang Liu

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:[email protected]"
align=baseline border=0></DIV>
++++++++++++++++++++++++++++++++++++++
I found the id of one of the parts which looks like an attachment, is
"(e-mail address removed)" 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

M.Liang Liu

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:[email protected]"
align=baseline border=0></DIV>
++++++++++++++++++++++++++++++++++++++
I found the id of one of the parts which looks like an attachment, is
"(e-mail address removed)" 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();
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,045
Latest member
DRCM

Latest Threads

Top