Commit a53361c1 by zhangxingmin

附件

parent 1a4d0340
...@@ -111,16 +111,32 @@ public class ApiEmailServiceImpl implements ApiEmailService { ...@@ -111,16 +111,32 @@ public class ApiEmailServiceImpl implements ApiEmailService {
// 判断是否有附件路径 // 判断是否有附件路径
if (StringUtils.isNotBlank(dto.getAttachmentPath())) { if (StringUtils.isNotBlank(dto.getAttachmentPath())) {
// 创建附件部分 // 按分号分割多个附件路径
MimeBodyPart attachmentPart = new MimeBodyPart(); String[] attachmentPaths = dto.getAttachmentPath().split(";");
// 创建文件数据源 for (String attachmentPath : attachmentPaths) {
DataSource source = new FileDataSource(dto.getAttachmentPath()); // 去除路径两端的空格
// 设置附件的数据处理器 attachmentPath = attachmentPath.trim();
attachmentPart.setDataHandler(new DataHandler(source)); // 检查路径是否非空
// 设置附件文件名(使用原文件名) if (StringUtils.isNotBlank(attachmentPath)) {
attachmentPart.setFileName(new File(dto.getAttachmentPath()).getName()); try {
// 将附件部分添加到多部分容器中 // 创建附件部分
multipart.addBodyPart(attachmentPart); MimeBodyPart attachmentPart = new MimeBodyPart();
// 创建文件数据源
DataSource source = new FileDataSource(attachmentPath);
// 设置附件的数据处理器
attachmentPart.setDataHandler(new DataHandler(source));
// 设置附件文件名(使用原文件名)
attachmentPart.setFileName(new File(attachmentPath).getName());
// 将附件部分添加到多部分容器中
multipart.addBodyPart(attachmentPart);
log.info("添加附件: {}", attachmentPath);
} catch (Exception e) {
log.error("添加附件失败: {}", attachmentPath, e);
// 可以选择继续处理其他附件,或者抛出异常
throw new RuntimeException("添加附件失败: " + attachmentPath, e);
}
}
}
} }
// 将多部分内容设置为邮件的完整内容 // 将多部分内容设置为邮件的完整内容
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment