内嵌查询代替LEFT JOIN导致的重复问题以及修改邮件不能发送图片和附件的问题
This commit is contained in:
@@ -26,8 +26,8 @@ import com.ruoyi.oa.domain.OaEmailAccount;
|
||||
import com.ruoyi.oa.mapper.OaEmailAccountMapper;
|
||||
import com.ruoyi.oa.service.IOaEmailAccountService;
|
||||
import com.ruoyi.oa.domain.request.EmailSendRequest;
|
||||
import cn.hutool.extra.mail.MailAccount;
|
||||
import cn.hutool.extra.mail.MailUtil;
|
||||
import com.ruoyi.oa.utils.EmailUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import java.util.List;
|
||||
@@ -45,6 +45,9 @@ import java.util.Collection;
|
||||
public class OaEmailAccountServiceImpl implements IOaEmailAccountService {
|
||||
|
||||
private final OaEmailAccountMapper baseMapper;
|
||||
|
||||
@Autowired
|
||||
private EmailUtil emailUtil;
|
||||
|
||||
/**
|
||||
* 查询发件人邮箱账号管理
|
||||
@@ -138,26 +141,60 @@ public class OaEmailAccountServiceImpl implements IOaEmailAccountService {
|
||||
int success = 0, fail = 0;
|
||||
StringBuilder failList = new StringBuilder();
|
||||
|
||||
if (type == 0 || type == 1) {
|
||||
// 网易/QQ邮箱 SMTP方式(已实现)
|
||||
MailAccount mailAccount = new MailAccount();
|
||||
mailAccount.setHost(account.getSmtpHost());
|
||||
mailAccount.setPort(account.getSmtpPort() == null ? 465 : account.getSmtpPort().intValue());
|
||||
mailAccount.setAuth(true);
|
||||
mailAccount.setFrom(account.getEmail());
|
||||
mailAccount.setUser(account.getEmail());
|
||||
mailAccount.setPass(account.getPassword());
|
||||
mailAccount.setSslEnable(true);
|
||||
if (type == 0 || type == 1) {
|
||||
// 网易/QQ邮箱 SMTP方式
|
||||
for (String to : request.getToList()) {
|
||||
try {
|
||||
MailUtil.send(mailAccount, to, request.getSubject(), request.getContent(), false);
|
||||
// 判断是否为HTML内容
|
||||
boolean isHtml = request.getContent() != null &&
|
||||
(request.getContent().contains("<html") ||
|
||||
request.getContent().contains("<div") ||
|
||||
request.getContent().contains("<p>"));
|
||||
|
||||
// 检查是否有附件
|
||||
boolean hasAttachments = request.getAttachmentPaths() != null && !request.getAttachmentPaths().isEmpty();
|
||||
// 检查是否有内嵌图片
|
||||
boolean hasInlineImages = request.getInlineImagePaths() != null && !request.getInlineImagePaths().isEmpty();
|
||||
|
||||
if (hasAttachments && hasInlineImages) {
|
||||
// 既有附件又有内嵌图片
|
||||
if (isHtml) {
|
||||
String processedContent = emailUtil.processHtmlWithInlineImages(request.getContent(), request.getInlineImagePaths());
|
||||
emailUtil.sendHtmlMailWithAttachmentsAndDynamicConfig(account, to, request.getSubject(), processedContent, request.getAttachmentPaths());
|
||||
} else {
|
||||
// 纯文本不支持内嵌图片,只发送附件
|
||||
emailUtil.sendMailWithAttachmentAndDynamicConfig(account, to, request.getSubject(), request.getContent(), request.getAttachmentPaths().get(0));
|
||||
}
|
||||
} else if (hasAttachments) {
|
||||
// 只有附件
|
||||
if (isHtml) {
|
||||
emailUtil.sendHtmlMailWithAttachmentsAndDynamicConfig(account, to, request.getSubject(), request.getContent(), request.getAttachmentPaths());
|
||||
} else {
|
||||
emailUtil.sendMailWithAttachmentAndDynamicConfig(account, to, request.getSubject(), request.getContent(), request.getAttachmentPaths().get(0));
|
||||
}
|
||||
} else if (hasInlineImages) {
|
||||
// 只有内嵌图片
|
||||
if (isHtml) {
|
||||
emailUtil.sendHtmlMailWithInlineImagesAndDynamicConfig(account, to, request.getSubject(), request.getContent(), request.getInlineImagePaths());
|
||||
} else {
|
||||
// 纯文本不支持内嵌图片
|
||||
emailUtil.sendMailWithDynamicConfig(account, to, request.getSubject(), request.getContent());
|
||||
}
|
||||
} else {
|
||||
// 无附件无内嵌图片
|
||||
if (isHtml) {
|
||||
emailUtil.sendHtmlMailWithDynamicConfig(account, to, request.getSubject(), request.getContent());
|
||||
} else {
|
||||
emailUtil.sendMailWithDynamicConfig(account, to, request.getSubject(), request.getContent());
|
||||
}
|
||||
}
|
||||
success++;
|
||||
} catch (Exception e) {
|
||||
fail++;
|
||||
failList.append(to).append(", ");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (type == 2) {
|
||||
// 阿里云邮件推送API
|
||||
for (String to : request.getToList()) {
|
||||
|
||||
Reference in New Issue
Block a user