mirror of
https://gitee.com/dromara/RuoYi-Vue-Plus.git
synced 2026-09-20 10:13:28 +08:00
[update]:
1. (framework) MailConfig - 初始化 JavaMailSender 改为直接初始化 MailAccount ; 2. (common) MailUtils - JavaMailSenderImpl 替换为 MailAccount ;
This commit is contained in:
parent
fbf8e6284a
commit
f199d202a5
@ -29,20 +29,13 @@ import java.util.Properties;
|
||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
public class MailUtils extends MailUtil {
|
||||
|
||||
private static final JavaMailSenderImpl SENDER = SpringUtils.getBean(JavaMailSenderImpl.class);
|
||||
|
||||
/**
|
||||
* 获取邮件发送实例
|
||||
*/
|
||||
public static JavaMailSender getSender() {
|
||||
return SENDER;
|
||||
}
|
||||
private static final MailAccount ACCOUNT = SpringUtils.getBean(MailAccount.class);
|
||||
|
||||
/**
|
||||
* 获取邮件发送实例
|
||||
*/
|
||||
public static MailAccount getMailAccount() {
|
||||
return getMailAccount(null, null);
|
||||
return ACCOUNT;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -52,19 +45,10 @@ public class MailUtils extends MailUtil {
|
||||
* @param password 授权码
|
||||
*/
|
||||
public static MailAccount getMailAccount(String username, String password) {
|
||||
Properties properties = SENDER.getJavaMailProperties();
|
||||
|
||||
MailAccount account = new MailAccount();
|
||||
account.setHost(SENDER.getHost());
|
||||
account.setPort(SENDER.getPort());
|
||||
account.setFrom(StringUtils.blankToDefault(username, SENDER.getUsername()));
|
||||
account.setUser(StringUtils.blankToDefault(username, SENDER.getUsername()));
|
||||
account.setPass(StringUtils.blankToDefault(password, SENDER.getPassword()));
|
||||
account.setAuth((Boolean) properties.get("mail.smtp.auth"));
|
||||
account.setDebug((Boolean) properties.get("mail.debug"));
|
||||
account.setStarttlsEnable((Boolean) properties.get("mail.smtp.starttls.enable"));
|
||||
|
||||
return account;
|
||||
ACCOUNT.setFrom(StringUtils.blankToDefault(username, ACCOUNT.getUser()));
|
||||
ACCOUNT.setUser(StringUtils.blankToDefault(username, ACCOUNT.getUser()));
|
||||
ACCOUNT.setPass(StringUtils.blankToDefault(password, ACCOUNT.getPass()));
|
||||
return ACCOUNT;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -1,13 +1,12 @@
|
||||
package com.ruoyi.framework.config;
|
||||
|
||||
import cn.hutool.extra.mail.MailAccount;
|
||||
import com.ruoyi.framework.config.properties.MailProperties;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.mail.javamail.JavaMailSenderImpl;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
* JavaMail 配置
|
||||
@ -21,25 +20,21 @@ public class MailConfig {
|
||||
private MailProperties mailProperties;
|
||||
|
||||
/**
|
||||
* 初始化 JavaMailSender
|
||||
* 初始化 MailAccount
|
||||
*/
|
||||
@Bean
|
||||
@ConditionalOnProperty(value = "spring.mail.enabled", havingValue = "true")
|
||||
public JavaMailSenderImpl getMailSender() {
|
||||
JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
|
||||
mailSender.setHost(mailProperties.getHost());
|
||||
mailSender.setPort(mailProperties.getPort());
|
||||
mailSender.setUsername(mailProperties.getUsername());
|
||||
mailSender.setPassword(mailProperties.getPassword());
|
||||
|
||||
Properties props = mailSender.getJavaMailProperties();
|
||||
props.put("mail.transport.protocol", mailProperties.getProtocol());
|
||||
props.put("mail.smtp.auth", mailProperties.getAuth());
|
||||
props.put("mail.smtp.starttls.enable", mailProperties.getStarttlsEnable());
|
||||
props.put("mail.smtp.ssl.trust", mailProperties.getSslTrust());
|
||||
props.put("mail.debug", mailProperties.getDebug());
|
||||
|
||||
return mailSender;
|
||||
public MailAccount mailAccount() {
|
||||
MailAccount account = new MailAccount();
|
||||
account.setUser(mailProperties.getUsername());
|
||||
account.setFrom(mailProperties.getUsername());
|
||||
account.setPass(mailProperties.getPassword());
|
||||
account.setHost(mailProperties.getHost());
|
||||
account.setPort(mailProperties.getPort());
|
||||
account.setAuth(mailProperties.getAuth());
|
||||
account.setDebug(mailProperties.getDebug());
|
||||
account.setStarttlsEnable(mailProperties.getStarttlsEnable());
|
||||
return account;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user