mirror of
https://github.com/dromara/RuoYi-Vue-Plus.git
synced 2025-09-24 07:19:46 +08:00
[add]:
1. (common) pom.xml - 增加邮件依赖 ; 2. (admin) application-dev.yml - 增加邮件配置 ; 3. (framework) MailProperties, MailConfig - 增加邮件属性配置 ; 4. (common) MailUtils - 重写 Hutool MailUtil方法 ; 5. (demo) MailController - 邮件发送测试方法 ;
This commit is contained in:
@ -0,0 +1,39 @@
|
||||
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 javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
* JavaMail 配置
|
||||
*
|
||||
* @author Michelle.Chung
|
||||
*/
|
||||
@Configuration
|
||||
public class MailConfig {
|
||||
|
||||
@Resource
|
||||
private MailProperties mailProperties;
|
||||
|
||||
/**
|
||||
* 初始化 JavaMailSender
|
||||
*/
|
||||
@Bean
|
||||
@ConditionalOnProperty(value = "spring.mail.enabled", havingValue = "true")
|
||||
public MailAccount mailAccount() {
|
||||
MailAccount account = new MailAccount();
|
||||
account.setFrom(mailProperties.getUsername());
|
||||
account.setUser(mailProperties.getUsername());
|
||||
account.setPass(mailProperties.getPassword());
|
||||
account.setPort(mailProperties.getPort());
|
||||
account.setAuth(mailProperties.getAuth());
|
||||
account.setDebug(mailProperties.getDebug());
|
||||
account.setStarttlsEnable(mailProperties.getStarttlsEnable());
|
||||
return account;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,65 @@
|
||||
package com.ruoyi.framework.config.properties;
|
||||
|
||||
import lombok.Data;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* JavaMail 配置属性
|
||||
*
|
||||
* @author Michelle.Chung
|
||||
*/
|
||||
@Data
|
||||
@Component
|
||||
@ConfigurationProperties(prefix = "spring.mail")
|
||||
public class MailProperties {
|
||||
|
||||
/**
|
||||
* 过滤开关
|
||||
*/
|
||||
private String enabled;
|
||||
|
||||
/**
|
||||
* 邮件服务地址
|
||||
*/
|
||||
private String host;
|
||||
|
||||
/**
|
||||
* 用户名
|
||||
*/
|
||||
private String username;
|
||||
|
||||
/**
|
||||
* 授权码 (设置 - 账户 - POP3/SMTP服务)
|
||||
*/
|
||||
private String password;
|
||||
|
||||
/**
|
||||
* 邮箱加密端口,不同邮箱的端口不一样
|
||||
*/
|
||||
private Integer port;
|
||||
|
||||
/**
|
||||
* 是否需要用户认证
|
||||
*/
|
||||
@Value("${spring.mail.properties.mail.smtp.auth}")
|
||||
private Boolean auth;
|
||||
|
||||
/**
|
||||
* 是否启用TLS加密
|
||||
*/
|
||||
@Value("${spring.mail.properties.mail.smtp.starttls.enable}")
|
||||
private Boolean starttlsEnable;
|
||||
|
||||
@Value("${spring.mail.properties.mail.smtp.ssl.trust}")
|
||||
private String sslTrust;
|
||||
|
||||
private Boolean debug;
|
||||
|
||||
/**
|
||||
* 传输协议 starttls.enable = true 时为 smtps
|
||||
*/
|
||||
private String protocol;
|
||||
|
||||
}
|
Reference in New Issue
Block a user