【发布时间】:2010-11-01 17:33:27
【问题描述】:
我想连同嵌入的图片一起发送邮件。为此,我使用了以下代码。它不是完整的代码。它是代码的一部分
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" />
请帮助我为什么图像没有显示在邮件中以及为什么它不在附件中??
【问题讨论】:
-
您是否检查过添加附件块是否被调用,即。该文件存在吗?
-
是的它正在执行..我已经检查了sop行n检查..那个块正在执行。
标签: java email jakarta-mail