使用 Javamail 附加内联图像时无法从 iphone 读取附件
Can't read attachment from iphone when using Javamail to attach inline image
当我将图像添加为 MimeBodyPart.INLINE 时,附件显示良好,但在 iphone 上除外,使用 javamail 将图像附加为签名的最佳方法是什么?
如果我删除 "imagePart",所有其他附件都可以正常工作
我用过:
MimeMessage m = new MimeMessage(session);
MimeMultipart content = new MimeMultipart("related");
// ContentID is used by both parts
String cid = ContentIdGenerator.getContentId();
// HTML part
String textPartSaine = Tools.convertSymbolToUTF8(emailContenu, true);
MimeBodyPart textPart = new MimeBodyPart();
textPart.setText("<html><head>"
+ "<title></title>"
+ "</head>\n"
+ "<body>"
+ "<div>"+ textPartSaine.replaceAll("\n", "<BR/>") +"</div><BR/><BR/>"
+ "<div><img src=\"cid:"
+ cid
+ "\" /></div><BR/><BR/>" + "</body></html>",
"US-ASCII", "html");
content.addBodyPart(textPart);
// Image part
if(signature != null && signature.exists()){
MimeBodyPart imagePart = new MimeBodyPart();
imagePart.attachFile(signature);
imagePart.setContentID("<" + cid + ">");
imagePart.setDisposition(MimeBodyPart.INLINE);
content.addBodyPart(imagePart);
}
if(fichiers != null && fichiers.length > 0) {
for(i = 0; i < fichiers.length; i++) {
partie = new MimeBodyPart();
partie.attachFile(fichiers[i]);
content.addBodyPart(partie);
}
}
谢谢
已解决
multipart/mixed(将包含正文和附件)
multipart/alternative(将包含文本和 HTML)
multipart/related(HTML + 嵌入图片)
image1(内容-Id:xxx)
图片2
...
附件1
附件2
...
当我将图像添加为 MimeBodyPart.INLINE 时,附件显示良好,但在 iphone 上除外,使用 javamail 将图像附加为签名的最佳方法是什么? 如果我删除 "imagePart",所有其他附件都可以正常工作
我用过:
MimeMessage m = new MimeMessage(session);
MimeMultipart content = new MimeMultipart("related");
// ContentID is used by both parts
String cid = ContentIdGenerator.getContentId();
// HTML part
String textPartSaine = Tools.convertSymbolToUTF8(emailContenu, true);
MimeBodyPart textPart = new MimeBodyPart();
textPart.setText("<html><head>"
+ "<title></title>"
+ "</head>\n"
+ "<body>"
+ "<div>"+ textPartSaine.replaceAll("\n", "<BR/>") +"</div><BR/><BR/>"
+ "<div><img src=\"cid:"
+ cid
+ "\" /></div><BR/><BR/>" + "</body></html>",
"US-ASCII", "html");
content.addBodyPart(textPart);
// Image part
if(signature != null && signature.exists()){
MimeBodyPart imagePart = new MimeBodyPart();
imagePart.attachFile(signature);
imagePart.setContentID("<" + cid + ">");
imagePart.setDisposition(MimeBodyPart.INLINE);
content.addBodyPart(imagePart);
}
if(fichiers != null && fichiers.length > 0) {
for(i = 0; i < fichiers.length; i++) {
partie = new MimeBodyPart();
partie.attachFile(fichiers[i]);
content.addBodyPart(partie);
}
}
谢谢
已解决 multipart/mixed(将包含正文和附件) multipart/alternative(将包含文本和 HTML) multipart/related(HTML + 嵌入图片) image1(内容-Id:xxx) 图片2 ... 附件1 附件2 ...