mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
add img for mail
This commit is contained in:
@@ -7,6 +7,7 @@
|
|||||||
|
|
||||||
### 新特性
|
### 新特性
|
||||||
* 【core】 改进CollUtil.zip逻辑,减少内存复制(issue#I10T01@Gitee)
|
* 【core】 改进CollUtil.zip逻辑,减少内存复制(issue#I10T01@Gitee)
|
||||||
|
* 【extra】 邮件支持图片(pr#495@Github)
|
||||||
|
|
||||||
### Bug修复
|
### Bug修复
|
||||||
* 【http】 修复HttpRquest中body方法长度计算问题(issue#I10UPG@Gitee)
|
* 【http】 修复HttpRquest中body方法长度计算问题(issue#I10UPG@Gitee)
|
||||||
|
@@ -21,6 +21,7 @@ import javax.mail.internet.MimeMessage;
|
|||||||
import javax.mail.internet.MimeMultipart;
|
import javax.mail.internet.MimeMultipart;
|
||||||
import javax.mail.util.ByteArrayDataSource;
|
import javax.mail.util.ByteArrayDataSource;
|
||||||
|
|
||||||
|
import cn.hutool.core.io.IoUtil;
|
||||||
import cn.hutool.core.util.ArrayUtil;
|
import cn.hutool.core.util.ArrayUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
|
||||||
@@ -349,18 +350,20 @@ public class Mail {
|
|||||||
|
|
||||||
// 图片
|
// 图片
|
||||||
for (Map.Entry<String, InputStream> entry : imageMap.entrySet()) {
|
for (Map.Entry<String, InputStream> entry : imageMap.entrySet()) {
|
||||||
BodyPart messageBodyPart = new MimeBodyPart();
|
MimeBodyPart imgBodyPart = new MimeBodyPart();
|
||||||
DataSource ds;
|
DataSource ds;
|
||||||
try {
|
try {
|
||||||
ds = new ByteArrayDataSource(entry.getValue(), "image/jpeg");
|
ds = new ByteArrayDataSource(entry.getValue(), "image/jpeg");
|
||||||
|
IoUtil.close(entry.getValue());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new MailException(e);
|
throw new MailException(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
messageBodyPart.setDataHandler(new DataHandler(ds));
|
imgBodyPart.setDataHandler(new DataHandler(ds));
|
||||||
messageBodyPart.setHeader("Content-ID", String.format("<%s>", entry.getKey()));
|
// imgBodyPart.setHeader("Content-ID", String.format("<%s>", entry.getKey()));
|
||||||
|
imgBodyPart.setContentID(entry.getKey());
|
||||||
// add it
|
// add it
|
||||||
mainPart.addBodyPart(messageBodyPart);
|
mainPart.addBodyPart(imgBodyPart);
|
||||||
}
|
}
|
||||||
|
|
||||||
return mainPart;
|
return mainPart;
|
||||||
|
Reference in New Issue
Block a user