parent
f9f895c518
commit
1e35045f67
@ -0,0 +1,35 @@
|
|||||||
|
package com.ruoyi.common.core.mail;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.experimental.Accessors;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 邮件头信息
|
||||||
|
*
|
||||||
|
* @since 2022/8/17
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Accessors(chain = true)
|
||||||
|
public class MailMessageHead {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 发件人
|
||||||
|
*/
|
||||||
|
private String from;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 收件人
|
||||||
|
*/
|
||||||
|
private String to;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 抄送
|
||||||
|
*/
|
||||||
|
private String cc;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 邮件标题(Subject)
|
||||||
|
*/
|
||||||
|
private String subject;
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,87 @@
|
|||||||
|
package com.ruoyi.common.core.mail;
|
||||||
|
|
||||||
|
import org.springframework.mail.javamail.JavaMailSenderImpl;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 邮件发送工具
|
||||||
|
* date 2021/8/18
|
||||||
|
*/
|
||||||
|
public interface MailSender {
|
||||||
|
|
||||||
|
String ADDRESS_SPLIT = ";";
|
||||||
|
|
||||||
|
//======================================= ↓↓↓ 快速构建 ↓↓↓ =======================================
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 构建发送工具
|
||||||
|
*
|
||||||
|
* @param senderAccount 发送账号
|
||||||
|
* @param enableDebug 是否开启debug信息输出
|
||||||
|
*/
|
||||||
|
static MailSender build(MailSendAccount senderAccount, int timeout, boolean enableDebug) {
|
||||||
|
return new SpringMailSender(senderAccount, timeout, enableDebug);
|
||||||
|
}
|
||||||
|
|
||||||
|
static MailSender build(MailSendAccount senderAccount, boolean enableDebug) {
|
||||||
|
return new SpringMailSender(senderAccount, 20000, enableDebug);
|
||||||
|
}
|
||||||
|
|
||||||
|
static MailSender build(MailSendAccount senderAccount) {
|
||||||
|
return new SpringMailSender(senderAccount);
|
||||||
|
}
|
||||||
|
|
||||||
|
//======================================= ↓↓↓ 主要API ↓↓↓ =======================================
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 发送MIME邮件
|
||||||
|
*
|
||||||
|
* @param form 发送参数
|
||||||
|
* @return 发送结果
|
||||||
|
*/
|
||||||
|
MailSendResult sendMail(MailMessage form);
|
||||||
|
|
||||||
|
default MailSendResult sendMail(String from, String to, String cc, String subject, String text, List<File> attachments) {
|
||||||
|
MailMessage message = new MailMessage()
|
||||||
|
.setFrom(from)
|
||||||
|
.setTo(to)
|
||||||
|
.setCc(cc)
|
||||||
|
.setSubject(subject)
|
||||||
|
.setContent(text)
|
||||||
|
.addAttachments(attachments);
|
||||||
|
return sendMail(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
default MailSendResult sendMail(String to, String cc, String subject, String text, List<File> attachments) {
|
||||||
|
return sendMail(null, to, cc, subject, text, attachments);
|
||||||
|
}
|
||||||
|
|
||||||
|
default MailSendResult sendMail(String to, String subject, String text, List<File> attachments) {
|
||||||
|
return sendMail(null, to, null, subject, text, attachments);
|
||||||
|
}
|
||||||
|
|
||||||
|
default MailSendResult sendMail(String to, String cc, String subject, String text) {
|
||||||
|
return sendMail(null, to, cc, subject, text, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
default MailSendResult sendMail(String to, String subject, String text) {
|
||||||
|
return sendMail(null, to, null, subject, text, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
//======================================= ↓↓↓ 其他API ↓↓↓ =======================================
|
||||||
|
|
||||||
|
MailSendAccount getSenderAccount();
|
||||||
|
|
||||||
|
JavaMailSenderImpl getExecutor();
|
||||||
|
|
||||||
|
void resetSenderAccount(MailSendAccount senderAccount);
|
||||||
|
|
||||||
|
default void resetSenderAccount(String host, int port, String username, String password) {
|
||||||
|
resetSenderAccount(new MailSendAccount(host, port, username, password, (password != null && !password.isEmpty())));
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean available();
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,81 @@
|
|||||||
|
package com.ruoyi.common.security.utils;
|
||||||
|
|
||||||
|
import com.ruoyi.common.core.constant.CacheConstants;
|
||||||
|
import com.ruoyi.common.core.utils.SpringUtils;
|
||||||
|
import com.ruoyi.common.redis.service.RedisService;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 系统参数工具类 (sys_config)
|
||||||
|
*
|
||||||
|
* @author Alan Scipio
|
||||||
|
* created on 2024/3/1
|
||||||
|
*/
|
||||||
|
public class SysConfigUtils {
|
||||||
|
|
||||||
|
private SysConfigUtils() {
|
||||||
|
throw new IllegalStateException("Utility class cannot be instantiated");
|
||||||
|
}
|
||||||
|
|
||||||
|
private static RedisService redisService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置参数缓存
|
||||||
|
*
|
||||||
|
* @param configKey 参数键
|
||||||
|
* @param configValue 参数值
|
||||||
|
*/
|
||||||
|
public static void setConfigCache(String configKey, String configValue) {
|
||||||
|
if (redisService == null) {
|
||||||
|
redisService = SpringUtils.getBean(RedisService.class);
|
||||||
|
}
|
||||||
|
redisService.setCacheObject(getCacheKey(configKey), configValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取参数缓存
|
||||||
|
*
|
||||||
|
* @param configKey 参数键
|
||||||
|
* @return configValue 参数值
|
||||||
|
*/
|
||||||
|
public static String getConfigCache(String configKey) {
|
||||||
|
if (redisService == null) {
|
||||||
|
redisService = SpringUtils.getBean(RedisService.class);
|
||||||
|
}
|
||||||
|
return redisService.getCacheObject(getCacheKey(configKey));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除指定参数缓存
|
||||||
|
*
|
||||||
|
* @param key 字典键
|
||||||
|
*/
|
||||||
|
public static void removeConfigCache(String key) {
|
||||||
|
if (redisService == null) {
|
||||||
|
redisService = SpringUtils.getBean(RedisService.class);
|
||||||
|
}
|
||||||
|
redisService.deleteObject(getCacheKey(key));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 清空所有参数缓存
|
||||||
|
*/
|
||||||
|
public static void clearConfigCaches() {
|
||||||
|
if (redisService == null) {
|
||||||
|
redisService = SpringUtils.getBean(RedisService.class);
|
||||||
|
}
|
||||||
|
Collection<String> keys = redisService.keys(CacheConstants.SYS_CONFIG_KEY + "*");
|
||||||
|
redisService.deleteObject(keys);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置cache key
|
||||||
|
*
|
||||||
|
* @param configKey 参数键
|
||||||
|
* @return 缓存键key
|
||||||
|
*/
|
||||||
|
public static String getCacheKey(String configKey) {
|
||||||
|
return CacheConstants.SYS_CONFIG_KEY + configKey;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue