修改邮件账号信息

pull/22/head
rays 2021-08-16 14:26:42 +08:00
parent b37dcb2244
commit ab3e4ff033
2 changed files with 27 additions and 45 deletions

View File

@ -24,7 +24,6 @@
*/
package cn.stylefeng.roses.kernel.email.jdk;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.extra.mail.MailAccount;
@ -32,6 +31,7 @@ import cn.hutool.extra.mail.MailUtil;
import cn.stylefeng.roses.kernel.email.api.MailSenderApi;
import cn.stylefeng.roses.kernel.email.api.exception.MailException;
import cn.stylefeng.roses.kernel.email.api.exception.enums.EmailExceptionEnum;
import cn.stylefeng.roses.kernel.email.api.expander.EmailConfigExpander;
import cn.stylefeng.roses.kernel.email.api.pojo.SendMailParam;
/**
@ -42,15 +42,6 @@ import cn.stylefeng.roses.kernel.email.api.pojo.SendMailParam;
*/
public class JavaMailSender implements MailSenderApi {
/**
*
*/
private final MailAccount mailAccount;
public JavaMailSender(MailAccount mailAccount) {
this.mailAccount = mailAccount;
}
@Override
public void sendMail(SendMailParam sendMailParam) {
@ -58,7 +49,7 @@ public class JavaMailSender implements MailSenderApi {
assertSendMailParams(sendMailParam);
//spring发送邮件
MailUtil.send(mailAccount, sendMailParam.getTos(), sendMailParam.getCcsTos(), sendMailParam.getBccsTos(), sendMailParam.getTitle(), sendMailParam.getContent(), sendMailParam.getImageMap(), false, sendMailParam.getFiles());
MailUtil.send(this.getConfigAccountInfo(), sendMailParam.getTos(), sendMailParam.getCcsTos(), sendMailParam.getBccsTos(), sendMailParam.getTitle(), sendMailParam.getContent(), sendMailParam.getImageMap(), false, sendMailParam.getFiles());
}
@Override
@ -68,7 +59,31 @@ public class JavaMailSender implements MailSenderApi {
assertSendMailParams(sendMailParam);
//spring发送邮件
MailUtil.send(mailAccount, sendMailParam.getTos(), sendMailParam.getCcsTos(), sendMailParam.getBccsTos(), sendMailParam.getTitle(), sendMailParam.getContent(), sendMailParam.getImageMap(), true, sendMailParam.getFiles());
MailUtil.send(this.getConfigAccountInfo(), sendMailParam.getTos(), sendMailParam.getCcsTos(), sendMailParam.getBccsTos(), sendMailParam.getTitle(), sendMailParam.getContent(), sendMailParam.getImageMap(), true, sendMailParam.getFiles());
}
/**
*
*
* @return {@link MailAccount}
* @author majianguo
* @date 2021/8/16 13:57
**/
private MailAccount getConfigAccountInfo() {
MailAccount mailAccount = new MailAccount();
// 配置默认都从系统配置表获取
mailAccount.setHost(EmailConfigExpander.getSmtpHost());
mailAccount.setPort(EmailConfigExpander.getSmtpPort());
mailAccount.setAuth(EmailConfigExpander.getSmtpAuthEnable());
mailAccount.setUser(EmailConfigExpander.getSmtpUser());
mailAccount.setPass(EmailConfigExpander.getSmtpPass());
mailAccount.setFrom(EmailConfigExpander.getSmtpFrom());
mailAccount.setStarttlsEnable(EmailConfigExpander.getStartTlsEnable());
mailAccount.setSslEnable(EmailConfigExpander.getSSLEnable());
mailAccount.setSocketFactoryPort(EmailConfigExpander.getSocketFactoryPort());
mailAccount.setTimeout(EmailConfigExpander.getTimeout());
mailAccount.setConnectionTimeout(EmailConfigExpander.getConnectionTimeout());
return mailAccount;
}
/**

View File

@ -24,12 +24,6 @@
*/
package cn.stylefeng.roses.kernel.email.starter;
import cn.hutool.extra.mail.MailAccount;
import cn.stylefeng.roses.kernel.email.api.MailSenderApi;
import cn.stylefeng.roses.kernel.email.api.expander.EmailConfigExpander;
import cn.stylefeng.roses.kernel.email.jdk.JavaMailSender;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
@ -41,31 +35,4 @@ import org.springframework.context.annotation.Configuration;
@Configuration
public class GunsEmailAutoConfiguration {
/**
* java mail
*
* @author fengshuonan
* @date 2020/12/1 11:32
*/
@Bean
@ConditionalOnMissingBean(MailSenderApi.class)
public MailSenderApi mailSenderApi() {
MailAccount mailAccount = new MailAccount();
// 配置默认都从系统配置表获取
mailAccount.setHost(EmailConfigExpander.getSmtpHost());
mailAccount.setPort(EmailConfigExpander.getSmtpPort());
mailAccount.setAuth(EmailConfigExpander.getSmtpAuthEnable());
mailAccount.setUser(EmailConfigExpander.getSmtpUser());
mailAccount.setPass(EmailConfigExpander.getSmtpPass());
mailAccount.setFrom(EmailConfigExpander.getSmtpFrom());
mailAccount.setStarttlsEnable(EmailConfigExpander.getStartTlsEnable());
mailAccount.setSslEnable(EmailConfigExpander.getSSLEnable());
mailAccount.setSocketFactoryPort(EmailConfigExpander.getSocketFactoryPort());
mailAccount.setTimeout(EmailConfigExpander.getTimeout());
mailAccount.setConnectionTimeout(EmailConfigExpander.getConnectionTimeout());
return new JavaMailSender(mailAccount);
}
}