在电子邮件中嵌入内嵌图像并通过cid引用它? [英] Embedding inline image in email and referring it thru cid?

查看:1162
本文介绍了在电子邮件中嵌入内嵌图像并通过cid引用它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将内嵌图像与带有mime消息的电子邮件一起发送.这是相同的简短代码.一切正常. 我的 问题是我没有将MimeMessage内容类型设置为multipart/related(也没有设置 仍然是我的代码可以正常工作,并且我能够在预期位置获得内嵌图片. 当我使用cid引用图像部分时,我是否真的应该关心将Content-Type设置为multipart/related? 或服务器来解决这个问题?

i am sending the inline image with email with mime message. Here is the brief code for the same. This is working fine. My question is i am not setting the MimeMessage content-type as multipart/related (Also not setting multipart subtype as related)still my code is working fine and iam able to get the inline image at expected postion. Should i really care about setting the Content-Type as multipart/related when i am referring the image part with cid or server takes care of that?

  MimeMessage   msg = new MimeMessage(mailSession);
  MimeMultipart mpart = new MimeMultipart();
  MimeBodyPart bp = new MimeBodyPart();
  bp.setText("plain text and here is html image refering image part <img src="cid:Unique-ContentId" />", CHARSET_UTF_8, MESSAGE_HTML_CONTENT_TYPE);
  // add message body
  mpart.addBodyPart(bp);

 // adding inline image  part
  MimeBodyPart bodyPart1 = new MimeBodyPart();
  bodyPart1.setFileName("inline image");
  file1 = new File("image1");
  DataSource source1 = new FileDataSource(file);
  bodyPart1.setDataHandler(new DataHandler(source));
  bodyPart1.setDisposition(MimeBodyPart.INLINE);
  bodyPart1.setHeader("Content-ID", "Unique-ContentId");
  bodyPart1.setHeader("Content-Type", "image/jpeg");
  mpart.addBodyPart(bodyPart1);

  // At last setting multipart In MimeMessage
  msg.setContent(mpart);

仅供参考,我的电子邮件客户端可以是Outlook,lotusnotes,yahoo,gmail,雷鸟

Just for information my email client can be outlook,lotusnotes,yahoo,gmail,thunderbird

推荐答案

这就是我们所说的运气". :-)

That's what we call "luck". :-)

显然,您使用的电子邮件客户端在解释您发送的消息时非常慷慨.电子邮件规范中没有任何内容表明他们应该以这种方式解释此类消息.

Apparently the email clients you're using are being very generous in the way they interpret the message you're sending. There's nothing in the email specs that suggest they should interpret such messages in this way.

这篇关于在电子邮件中嵌入内嵌图像并通过cid引用它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆