Domanda

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);

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

È stato utile?

Soluzione

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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top