Skip to content

Commit

Permalink
feat(util): 根据SSLAuthVerify配置动态调整邮件发送配置
Browse files Browse the repository at this point in the history
  • Loading branch information
shulng committed Jul 13, 2024
1 parent 19a86d9 commit 9211ecd
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
18 changes: 11 additions & 7 deletions src/main/java/cc/baka9/catseedlogin/util/Mail.java
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
package cc.baka9.catseedlogin.util;


import cc.baka9.catseedlogin.bukkit.Config;
import java.util.Date;
import java.util.Properties;

import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import java.util.Date;
import java.util.Properties;

import cc.baka9.catseedlogin.bukkit.Config;

public class Mail {

private Mail(){
private Mail() {
}


public static void sendMail(String receiveMailAccount, String subject, String content) throws Exception{
public static void sendMail(String receiveMailAccount, String subject, String content) throws Exception {

Properties props = new Properties();
props.setProperty("mail.transport.protocol", "smtp");
Expand All @@ -30,6 +29,11 @@ public static void sendMail(String receiveMailAccount, String subject, String co
props.setProperty("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
props.setProperty("mail.smtp.socketFactory.fallback", "false");
props.setProperty("mail.smtp.socketFactory.port", smtpPort);
} else {
// 如果 SSLAuthVerify 为 false,移除 SSL 相关的配置
props.remove("mail.smtp.socketFactory.class");
props.remove("mail.smtp.socketFactory.fallback");
props.remove("mail.smtp.socketFactory.port");
}

String emailAccount = Config.EmailVerify.EmailAccount;
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/emailVerify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ EmailAccount: "[email protected]"
EmailPassword: "123456"
EmailSmtpHost: "smtp.qq.com"
EmailSmtpPort: "465"
SSLAuthVerify: true
FromPersonal: "xxx服务器"
SSLAuthVerify: false
FromPersonal: "xxx服务器"

0 comments on commit 9211ecd

Please sign in to comment.