Compare commits
No commits in common. 'master' and 'duhanyu' have entirely different histories.
@ -1,83 +0,0 @@
|
||||
package com.ruoyi.jjh.declaration.component;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.mail.*;
|
||||
import javax.mail.internet.AddressException;
|
||||
import javax.mail.internet.InternetAddress;
|
||||
import javax.mail.internet.MimeMessage;
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
* 发送邮件业务处理层
|
||||
* @author du
|
||||
* @since 2024/12/12 9:55
|
||||
*/
|
||||
@Component("EmailEnterImpl")
|
||||
public class EmailEnterImpl implements EmailEnterService{
|
||||
|
||||
/**
|
||||
* 是否是正式环境
|
||||
*/
|
||||
@Value("${isTiming}")
|
||||
private Boolean isTiming;
|
||||
|
||||
/**
|
||||
* SMTP 服务器
|
||||
*/
|
||||
@Value("${smtp}")
|
||||
private String smtp;
|
||||
|
||||
/**
|
||||
* SMTP IP
|
||||
*/
|
||||
@Value("${smtpIp}")
|
||||
private String smtpIp;
|
||||
|
||||
/**
|
||||
* SMTP 端口
|
||||
*/
|
||||
@Value("${smtpDk}")
|
||||
private String smtpDk;
|
||||
|
||||
/**
|
||||
* 根据邮箱地址发送邮件
|
||||
*/
|
||||
@Override
|
||||
public Boolean toEnter(String subject, String body,String toEmail) {
|
||||
// 发件人邮箱的登录凭证
|
||||
String username = "jjdn@sipac.gov.cn"; // 发件人邮箱用户名(一般为邮箱地址)
|
||||
String password = "N!4lsU.T_#2T2Z"; // 发件人邮箱的授权码
|
||||
// 设置邮件服务器属性
|
||||
Properties properties = new Properties();
|
||||
properties.put("mail.smtp.host", smtpIp);
|
||||
properties.put("mail.smtp.port", smtpDk);
|
||||
properties.put("mail.smtp.auth", "true"); // 启用身份验证
|
||||
properties.put("mail.smtp.starttls.enable", "true"); // 启用 TLS
|
||||
// 获取邮件会话
|
||||
Session session = Session.getInstance(properties, new Authenticator() {
|
||||
@Override
|
||||
protected PasswordAuthentication getPasswordAuthentication() {
|
||||
return new PasswordAuthentication(username, password);
|
||||
}
|
||||
});
|
||||
// 获取邮件会话
|
||||
try {
|
||||
// 创建邮件消息
|
||||
MimeMessage message = new MimeMessage(session);
|
||||
message.setFrom(new InternetAddress(username));
|
||||
message.addRecipient(Message.RecipientType.TO, new InternetAddress(toEmail));
|
||||
message.setSubject(subject);
|
||||
message.setText(body);
|
||||
// 发送邮件
|
||||
Transport.send(message);
|
||||
System.out.println("邮件发送成功");
|
||||
} catch (AddressException e) {
|
||||
e.printStackTrace();
|
||||
} catch (MessagingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
package com.ruoyi.jjh.declaration.component;
|
||||
|
||||
/**
|
||||
* 发送邮件业务层
|
||||
* @author du
|
||||
* @since 2024/12/12 9:50
|
||||
*/
|
||||
public interface EmailEnterService {
|
||||
/**
|
||||
* 根据邮箱地址发送邮件
|
||||
*/
|
||||
Boolean toEnter(String subject, String body,String toEmail);
|
||||
}
|
@ -1,29 +0,0 @@
|
||||
package com.ruoyi.jjh.declaration.config;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.scheduling.annotation.EnableAsync;
|
||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
||||
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
|
||||
/**
|
||||
* @author du
|
||||
* @since 2025/1/7 15:49
|
||||
*/
|
||||
@Configuration
|
||||
@EnableAsync
|
||||
public class AsyncConfig {
|
||||
@Bean(name ="chrisThreadPool")
|
||||
public Executor taskExecutor() {
|
||||
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
|
||||
executor.setCorePoolSize(10);
|
||||
executor.setMaxPoolSize(50);
|
||||
executor.setQueueCapacity(100);
|
||||
executor.setThreadNamePrefix("chrisThread-");
|
||||
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.AbortPolicy());
|
||||
executor.initialize();
|
||||
return executor;
|
||||
}
|
||||
}
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in new issue