mirror of
https://gitee.com/dromara/hutool.git
synced 2025-04-05 17:37:59 +08:00
!1279 修复MailUtil发送html格式邮件无法正常展示图片问题
* bugfix mail:图片附件设置内联,能够正常引用附件图片 * bugfix mail:图片附件设置内联,能够正常引用附件图片
This commit is contained in:
parent
a06b7a32aa
commit
e81e077b4c
@ -268,6 +268,8 @@ public class JakartaMail implements Builder<MimeMessage> {
|
||||
if (StrUtil.startWith(attachment.getContentType(), "image/")) {
|
||||
// 图片附件,用于正文中引用图片
|
||||
bodyPart.setContentID(nameEncoded);
|
||||
// 图片附件设置内联,否则无法正常引用图片
|
||||
bodyPart.setDisposition(MimeBodyPart.INLINE);
|
||||
}
|
||||
this.multipart.addBodyPart(bodyPart);
|
||||
}
|
||||
|
@ -8,10 +8,7 @@ import cn.hutool.core.util.ArrayUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
|
||||
import javax.activation.DataHandler;
|
||||
import javax.activation.DataSource;
|
||||
import javax.activation.FileDataSource;
|
||||
import javax.activation.FileTypeMap;
|
||||
import javax.activation.*;
|
||||
import javax.mail.Address;
|
||||
import javax.mail.MessagingException;
|
||||
import javax.mail.Multipart;
|
||||
@ -273,6 +270,8 @@ public class Mail implements Builder<MimeMessage> {
|
||||
if (StrUtil.startWith(attachment.getContentType(), "image/")) {
|
||||
// 图片附件,用于正文中引用图片
|
||||
bodyPart.setContentID(nameEncoded);
|
||||
// 图片附件设置内联,否则无法正常引用图片
|
||||
bodyPart.setDisposition(MimeBodyPart.INLINE);
|
||||
}
|
||||
this.multipart.addBodyPart(bodyPart);
|
||||
}
|
||||
|
@ -38,6 +38,15 @@ public class JakartaMailTest {
|
||||
JakartaMailUtil.sendHtml("hutool@foxmail.com", "测试", "<h1>邮件来自Hutool测试</h1><img src=\"cid:testImage\" />", map);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Disabled
|
||||
public void sendHtmlWithImageTest() {
|
||||
Map<String, InputStream> map = new HashMap<>();
|
||||
InputStream in = getClass().getClassLoader().getResourceAsStream("image/Dromara.png");
|
||||
map.put("<image-1>", in);
|
||||
JakartaMailUtil.sendHtml("hutool@foxmail.com;li7hai26@outlook.com", "测试", "<h1>邮件来自Hutool测试</h1><img src=\"cid:image-1\" />", map);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Disabled
|
||||
public void sendHtmlTest() {
|
||||
|
@ -38,6 +38,15 @@ public class MailTest {
|
||||
MailUtil.sendHtml("hutool@foxmail.com", "测试", "<h1>邮件来自Hutool测试</h1><img src=\"cid:testImage\" />", map);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Disabled
|
||||
public void sendHtmlWithImageTest() {
|
||||
Map<String, InputStream> map = new HashMap<>();
|
||||
InputStream in = getClass().getClassLoader().getResourceAsStream("image/Dromara.png");
|
||||
map.put("<image-1>", in);
|
||||
MailUtil.sendHtml("hutool@foxmail.com;li7hai26@outlook.com", "测试", "<h1>邮件来自Hutool测试</h1><img src=\"cid:image-1\" />", map);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Disabled
|
||||
public void sendHtmlTest() {
|
||||
|
BIN
hutool-extra/src/test/resources/image/Dromara.png
Normal file
BIN
hutool-extra/src/test/resources/image/Dromara.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 29 KiB |
Loading…
Reference in New Issue
Block a user