Commit a53361c1 by zhangxingmin

附件

parent 1a4d0340
......@@ -111,16 +111,32 @@ public class ApiEmailServiceImpl implements ApiEmailService {
// 判断是否有附件路径
if (StringUtils.isNotBlank(dto.getAttachmentPath())) {
// 创建附件部分
MimeBodyPart attachmentPart = new MimeBodyPart();
// 创建文件数据源
DataSource source = new FileDataSource(dto.getAttachmentPath());
// 设置附件的数据处理器
attachmentPart.setDataHandler(new DataHandler(source));
// 设置附件文件名(使用原文件名)
attachmentPart.setFileName(new File(dto.getAttachmentPath()).getName());
// 将附件部分添加到多部分容器中
multipart.addBodyPart(attachmentPart);
// 按分号分割多个附件路径
String[] attachmentPaths = dto.getAttachmentPath().split(";");
for (String attachmentPath : attachmentPaths) {
// 去除路径两端的空格
attachmentPath = attachmentPath.trim();
// 检查路径是否非空
if (StringUtils.isNotBlank(attachmentPath)) {
try {
// 创建附件部分
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