Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
C
cmeeting
概览
概览
详情
活动
周期分析
版本库
存储库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
Issue Boards
Open sidebar
翟斌
cmeeting
Commits
ce408f63
提交
ce408f63
authored
7月 30, 2025
作者:
洪东保
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
yml配置去掉邮箱
父级
234d0d6b
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
7 行增加
和
116 行删除
+7
-116
src/main/java/com/cmeeting/email/EmailSender.java
+5
-113
src/main/resources/application.yml
+2
-3
没有找到文件。
src/main/java/com/cmeeting/email/EmailSender.java
浏览文件 @
ce408f63
...
...
@@ -6,6 +6,7 @@ import com.azure.identity.ClientSecretCredential;
import
com.azure.identity.ClientSecretCredentialBuilder
;
import
com.cmeeting.ad.service.UserService
;
import
com.cmeeting.ad.vo.UserVo
;
import
com.cmeeting.exception.RobotBaseException
;
import
com.cmeeting.log.service.ProcessLogService
;
import
com.cmeeting.util.RedisUtils
;
import
com.cmeeting.vo.EmailPush
;
...
...
@@ -46,8 +47,8 @@ import java.util.concurrent.atomic.AtomicInteger;
public
class
EmailSender
{
@Value
(
"${email.sender}"
)
private
String
SENDER
;
@Value
(
"${email.sender-pwd}"
)
private
String
EMAIL_PWD
;
//
@Value("${email.sender-pwd}")
//
private String EMAIL_PWD;
@Value
(
"${email.push-switch}"
)
private
Boolean
pushSwitch
;
@Value
(
"${email.environment}"
)
...
...
@@ -65,112 +66,6 @@ public class EmailSender {
@Resource
private
RedisUtils
redisUtils
;
/**
* @param toEmail 收件人
* @param subject 邮件主题
* @param attachmentPath 附件路径
* @param meetingId 会议id
* @return
*/
// public boolean sendEmailWithAttachment(String toEmail, String subject, String attachmentPath, String meetingId) {
// log.info("sendEmailWithAttachment start...");
// // 邮件服务器配置
// Properties props = new Properties();
// props.put("mail.smtp.host", SMTP_HOST);
// props.put("mail.smtp.auth", "true");
//
// props.put("mail.smtp.port", "587");
// props.put("mail.smtp.starttls.enable", "true"); // 使用TLS
// props.put("mail.smtp.starttls.required", "true");
// props.put("mail.debug", "true");
// props.put("mail.smtp.connectiontimeout", "5000"); // 连接超时时间(毫秒)
// props.put("mail.smtp.timeout", "5000"); // 读取超时时间(毫秒)
// props.remove("mail.smtp.user");
// props.remove("mail.user");
// props.remove("mail.smtp.ssl.enable");
//
// // 创建会话
// log.info("sender->{},email_pwd->{}",SENDER, EMAIL_PWD);
//
// System.getProperties().stringPropertyNames().stream()
// .filter(name -> name.startsWith("mail."))
// .forEach(name -> log.info(name + " = " + System.getProperty(name)));
//
// Session session = Session.getInstance(props); // 不传递 Authenticator
// String body = "您好:\n" +
// "\n" +
// " 附件为您本次会议的会议纪要,烦请下载查看";
//
// AtomicInteger retryCount = new AtomicInteger(0);
// boolean isSent = false;
// if(StringUtils.isEmpty(toEmail)){
// log.error("收件邮箱为空,推送失败");
// processLogService.log(meetingId,null,"收件邮箱为空,推送失败");
// return false;
// }
// log.info("准备开始邮件推送...");
// while (retryCount.intValue() < MAX_RETRY && !isSent){
// try {
// Transport transport = session.getTransport("smtp");
// // 创建邮件消息
// Message message = new MimeMessage(session);
// message.setFrom(new InternetAddress("cmeeting_assistant@cimc.com"));
// message.setRecipients(Message.RecipientType.TO,
// InternetAddress.parse(toEmail));
// message.setSubject(subject);
//
// // 创建消息体部分(正文)
// MimeBodyPart messageBodyPart = new MimeBodyPart();
// messageBodyPart.setText(body);
//
// // 创建多部分消息
// Multipart multipart = new MimeMultipart();
//
// // 添加文本部分
// multipart.addBodyPart(messageBodyPart);
//
// // 添加附件部分
// if (attachmentPath != null && !attachmentPath.isEmpty()) {
// MimeBodyPart attachmentPart = new MimeBodyPart();
// DataSource source = new FileDataSource(attachmentPath);
// attachmentPart.setDataHandler(new DataHandler(source));
// attachmentPart.setFileName(new File(attachmentPath).getName());
// multipart.addBodyPart(attachmentPart);
// }
//
// // 设置完整消息内容
// message.setContent(multipart);
//
// // 发送邮件
// log.info("Transport.send...");
//// Transport.send(message);
// transport.connect("smtp.office365.com", 587, "cmeeting_assistant@cimc.com", "scyou@xih45g6@xih4");
// transport.sendMessage(message, message.getAllRecipients());
// transport.close();
// log.error("邮件已成功发送: meetingId->{}", meetingId);
// isSent = true;
// }catch (Exception e) {
// retryCount.getAndIncrement();
// // 异常处理
// StringWriter sw = new StringWriter();
// PrintWriter pw = new PrintWriter(sw);
// e.printStackTrace(pw);
// processLogService.log(meetingId,null,"【邮件推送异常】:"+sw.toString());
// if (retryCount.intValue() > MAX_RETRY) {
// log.error("邮件发送达到最大重试次数: meetingId->{}", meetingId);
// throw new RuntimeException(e);
// }
// // 指数退避
// try {
// Thread.sleep((long) Math.pow(2, retryCount.intValue()) * 1000);
// } catch (InterruptedException ie) {
// Thread.currentThread().interrupt();
// throw new RuntimeException("邮件发送重试失败", ie);
// }
// }
// }
// return isSent;
// }
/**
* 发送邮件,带附件
...
...
@@ -178,10 +73,7 @@ public class EmailSender {
* @return
*/
public
boolean
sendEmailWithAttachment
(
EmailPush
emailPushBuilder
)
{
log
.
info
(
"sendEmailWithAttachment start..."
);
// 创建会话
log
.
info
(
"sender->{},email_pwd->{}"
,
SENDER
,
EMAIL_PWD
);
log
.
info
(
"sendEmailWithAttachment start, sender -> {}"
,
SENDER
);
if
(!
pushSwitch
){
log
.
info
(
"【邮箱推送】:应用未开启邮件推送功能"
);
...
...
@@ -249,7 +141,7 @@ public class EmailSender {
}
else
{
isSent
=
false
;
processLogService
.
log
(
meetingId
,
subMeetingId
,
"【邮件推送异常】:邮件模板未设置"
);
continue
;
throw
new
RobotBaseException
(
"邮件模板未设置"
)
;
}
message
.
body
=
body
;
...
...
src/main/resources/application.yml
浏览文件 @
ce408f63
...
...
@@ -39,8 +39,7 @@ CORP_SECRET: 7YLePWG7rJqkQFnAB4FeylqAXpmu7q5qv_NOeSGNbm0
############################################################## email
EMAIL_SENDER
:
cmeeting_assistant@cimc.com
#EMAIL_SENDER_PWD: scyou@xih45g6@xih4
EMAIL_SENDER_PWD
:
ENC(bH585hgTtUY5KpMgFqFpNRyL4kI/G7czZUk/7+U+LZY=)
#EMAIL_SENDER_PWD: ENC(bH585hgTtUY5KpMgFqFpNRyL4kI/G7czZUk/7+U+LZY=)
EMAIL_SMTP_HOST
:
smtp.office365.com
############################################################## permission
...
...
@@ -118,7 +117,7 @@ tencent:
email
:
sender
:
${EMAIL_SENDER}
sender-pwd
:
${EMAIL_SENDER_PWD}
#
sender-pwd: ${EMAIL_SENDER_PWD}
smtp-host
:
${EMAIL_SMTP_HOST}
push-switch
:
true
#邮件推送总开关,高优先级
environment
:
test
#test推给本公司人员,prod推给用户
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论