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
435d4e07
Commit
435d4e07
authored
Sep 24, 2025
by
zhangxingmin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
xxl-job
parent
aca1eeb8
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
11 additions
and
3 deletions
+11
-3
yd-email-api/src/main/java/com/yd/email/api/handler/MailSendJobHandler.java
+4
-2
yd-email-api/src/main/java/com/yd/email/api/service/impl/ApiEmailServiceImpl.java
+7
-1
No files found.
yd-email-api/src/main/java/com/yd/email/api/handler/MailSendJobHandler.java
View file @
435d4e07
package
com
.
yd
.
email
.
api
.
handler
;
import
com.alibaba.fastjson.JSON
;
import
com.xxl.job.core.context.XxlJobHelper
;
import
com.xxl.job.core.handler.annotation.XxlJob
;
import
com.yd.email.api.service.ApiEmailService
;
...
...
@@ -42,7 +43,6 @@ public class MailSendJobHandler {
public
void
execute
()
throws
Exception
{
// 从XXL-Job参数中获取任务ID
String
param
=
XxlJobHelper
.
getJobParam
();
// 记录任务开始日志
log
.
info
(
"开始执行邮件发送任务,参数: {}"
,
param
);
...
...
@@ -50,6 +50,7 @@ public class MailSendJobHandler {
String
taskBizId
=
param
;
// 根据邮件任务业务ID查询邮件任务信息
EmailTask
emailTask
=
iEmailTaskService
.
queryOne
(
taskBizId
);
log
.
info
(
"根据邮件任务业务ID查询邮件任务信息: {}: "
+
JSON
.
toJSONString
(
emailTask
));
// 检查邮件任务是否存在
if
(
Objects
.
isNull
(
emailTask
))
{
...
...
@@ -66,6 +67,7 @@ public class MailSendJobHandler {
try
{
// 查询该任务下的所有收件人信息
List
<
EmailTaskRecipients
>
recipients
=
iEmailTaskRecipientsService
.
queryList
(
taskBizId
);
log
.
info
(
"查询该任务下的所有收件人信息: {}: "
+
JSON
.
toJSONString
(
recipients
));
// 初始化成功和失败计数器
int
successCount
=
0
;
...
...
@@ -78,7 +80,7 @@ public class MailSendJobHandler {
List
<
String
>
ccList
=
StringUtils
.
isNotBlank
(
recipient
.
getCcEmail
())
?
Arrays
.
asList
(
recipient
.
getCcEmail
().
split
(
","
))
:
new
ArrayList
<>();
log
.
info
(
"处理抄送人列表:将数据库中的逗号分隔字符串转换为List: {}: "
+
JSON
.
toJSONString
(
ccList
));
// 调用邮件服务发送邮件
apiEmailService
.
sendMail
(
emailTask
.
getSendEmail
(),
// 发件人地址
...
...
yd-email-api/src/main/java/com/yd/email/api/service/impl/ApiEmailServiceImpl.java
View file @
435d4e07
package
com
.
yd
.
email
.
api
.
service
.
impl
;
import
com.alibaba.fastjson.JSON
;
import
com.yd.email.api.service.ApiEmailService
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang3.StringUtils
;
...
...
@@ -44,7 +45,7 @@ public class ApiEmailServiceImpl implements ApiEmailService {
@Override
public
void
sendMail
(
String
from
,
String
to
,
List
<
String
>
cc
,
String
subject
,
String
content
,
String
attachmentPath
)
throws
Exception
{
log
.
info
(
"发送邮件的主要方法参数: {}: "
+
from
+
";"
+
to
+
";"
+
JSON
.
toJSONString
(
cc
)
+
";"
+
subject
+
";"
+
content
);
// 创建邮件配置属性对象
Properties
props
=
new
Properties
();
// 设置SMTP需要身份验证
...
...
@@ -53,6 +54,9 @@ public class ApiEmailServiceImpl implements ApiEmailService {
props
.
put
(
"mail.smtp.starttls.enable"
,
"true"
);
// 设置邮件服务器主机名
props
.
put
(
"mail.smtp.host"
,
host
);
log
.
info
(
"mail.smtp.host:{}"
,
host
);
log
.
info
(
"spring.mail.username:{}"
,
username
);
log
.
info
(
"spring.mail.password:{}"
,
password
);
// 设置邮件服务器端口号(587是TLS标准端口)
props
.
put
(
"mail.smtp.port"
,
"587"
);
...
...
@@ -65,6 +69,7 @@ public class ApiEmailServiceImpl implements ApiEmailService {
}
});
log
.
info
(
"创建邮件会话对象,传入配置和认证器:{}"
,
JSON
.
toJSONString
(
session
));
// 使用try-catch块处理邮件发送异常
try
{
// 创建MIME类型邮件消息对象
...
...
@@ -118,6 +123,7 @@ public class ApiEmailServiceImpl implements ApiEmailService {
Transport
.
send
(
message
);
// 记录成功日志
log
.
info
(
"邮件发送成功: {} -> {}"
,
from
,
to
);
log
.
info
(
"发送邮件Transport.send(message) {}"
,
JSON
.
toJSONString
(
message
));
}
catch
(
MessagingException
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