java - 防止附加内联图像
问题描述
我有一个发送电子邮件的方法,签名是:
public void sendEmail(String to, File[] fileAttachments, String subject,
String body, boolean inlineImages) throws Exception {
我最近对其进行了修改,使其能够内联发送图像(在 HTML 电子邮件中)而不是附件。处理附件的方法体是:
MimeBodyPart messageBodyPart = new MimeBodyPart();
// messageBodyPart.setText(body);
messageBodyPart.setContent(body, "text/html; charset=utf-8");
Multipart multipart = new MimeMultipart();
multipart.addBodyPart(messageBodyPart);
if (fileAttachments != null) {
for( File f : fileAttachments ) {
messageBodyPart = new MimeBodyPart();
DataSource source = new FileDataSource(f);
messageBodyPart.setDataHandler(new DataHandler(source));
if( inlineImages ) {
messageBodyPart.setHeader("Content-ID", "<image>");
} else
messageBodyPart.setFileName(f.getName());
multipart.addBodyPart(messageBodyPart);
}
}
// Put parts in message
message.setContent(multipart);
// Send the message
Transport.send(message);
不幸的是,它现在以内联和附件的形式发送图像。如何修改代码,使其不附加图像,如果它是内联的?
解决方案
推荐阅读
- dart - Flutter ListView.builder 插入后不更新
- php - 用php计算年龄
- python - 修复 UnboundLocalError
- android - 什么数据被发送到 Fabric 服务器?[织物/Crashlytics]
- android - Android 工具栏背景
- javascript - 用逗号分割对象,然后将其添加到 hbs 文件中
- android - 我们可以在 FragmentPagerAdapter 上使用 Activity Intent 吗?
- php - symfony - 我如何使用验证组获取整个实体?
- nativescript - 如何使用 Nativescript 获得手机的电源寿命?
- charts - 数据注释排列