【发布时间】:2019-05-20 15:43:56
【问题描述】:
我想将内嵌图像发送到电子邮件。我尝试了几乎所有可能的方法,但没有运气。
我可以将图像添加为内联图像,但它们也出现在附件中,所以我无法避免这个附件。
messageBodyPart = new MimeBodyPart();
String htmlText = "<H1>This is the image: </H1><img src=\"cid:image\">";
((MimeBodyPart) messageBodyPart).setText(htmlText, null, "html");
mp.addBodyPart(messageBodyPart);
// second part (the image)
messageBodyPart = new MimeBodyPart();
String filePath = "abc.png";
((MimeBodyPart) messageBodyPart).attachFile(filePath, "image/png", "base64");
((MimeBodyPart) messageBodyPart).setContentID("<image>");
mp.addBodyPart( messageBodyPart );
我也尝试过使用messageBodyPart.setDisposition( MimePart.INLINE );,但还是不行。
【问题讨论】:
标签: java spring-boot jakarta-mail