画像を埋め込んでメールを送信したい。そのために、以下のコードを使用しました。完全なコードではありません。そのコードの一部
Multipart multipart = new MimeMultipart("related");
// Create the message part
BodyPart messageBodyPart;
messageBodyPart = new MimeBodyPart();
messageBodyPart.setText(msgBody); // msgbody contains the contents of the html file
messageBodyPart.setHeader("Content-Type", "text/html");
multipart.addBodyPart(messageBodyPart);
//add file attachments
DataSource source;
File file = new File("D:/sample.jpeg");
if(file.exists()){
// add attachment
messageBodyPart = new MimeBodyPart();
source = new FileDataSource(file);
messageBodyPart.setDataHandler(new DataHandler(source));
messageBodyPart.setFileName(file.getName());
messageBodyPart.setHeader("Content-ID", "<BarcodeImage>");
messageBodyPart.setDisposition("inline");
multipart.addBodyPart(messageBodyPart);
}
// Put parts in message
msg.setContent(multipart);
Transport.send(msg);
私が直面している問題は、メールを受け取ることはできますが、画像を見ることができません..メールに表示されません。
以下はhtmlファイルの私の部分です
<img src=\"cid:BarcodeImage\" alt="Barcode" width="166" height="44" align="right" />
画像がメールに表示されない理由と添付ファイルにない理由を教えてください??