Commit 82a0b89d by zhangxingmin

push

parent 4be82047
......@@ -134,7 +134,7 @@ public class ApiEmailServiceImpl implements ApiEmailService {
Multipart multipart = new MimeMultipart();
multipart.addBodyPart(messageBodyPart);
// 多附件处理逻辑(您之前添加的)
// 修改附件处理部分:
if (StringUtils.isNotBlank(dto.getAttachmentPath())) {
String[] attachmentPaths = dto.getAttachmentPath().split(";");
for (String attachmentPath : attachmentPaths) {
......@@ -142,13 +142,27 @@ public class ApiEmailServiceImpl implements ApiEmailService {
if (StringUtils.isNotBlank(attachmentPath)) {
try {
MimeBodyPart attachmentPart = new MimeBodyPart();
DataSource source = new FileDataSource(attachmentPath);
DataSource source;
String fileName;
if (attachmentPath.startsWith("http://") || attachmentPath.startsWith("https://")) {
// 使用URLDataSource处理网络附件
URL url = new URL(attachmentPath);
source = new URLDataSource(url);
fileName = getFileNameFromUrl(attachmentPath);
} else {
// 处理本地文件附件
source = new FileDataSource(attachmentPath);
fileName = new File(attachmentPath).getName();
}
attachmentPart.setDataHandler(new DataHandler(source));
attachmentPart.setFileName(new File(attachmentPath).getName());
attachmentPart.setFileName(fileName);
multipart.addBodyPart(attachmentPart);
log.info("成功添加附件: {}", attachmentPath);
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