Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yd-email
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
xingmin
yd-email
Commits
a53361c1
Commit
a53361c1
authored
Sep 28, 2025
by
zhangxingmin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
附件
parent
1a4d0340
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
10 deletions
+26
-10
yd-email-api/src/main/java/com/yd/email/api/service/impl/ApiEmailServiceImpl.java
+26
-10
No files found.
yd-email-api/src/main/java/com/yd/email/api/service/impl/ApiEmailServiceImpl.java
View file @
a53361c1
...
...
@@ -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
);
}
}
}
}
// 将多部分内容设置为邮件的完整内容
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment