Merge pull request '2025-10-09 16:27 乔毅凡合并' (#4) from qiaoyifan_branch into develop
commit
f4ba30bca1
@ -1,13 +1,86 @@
|
||||
package Base;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Properties;
|
||||
|
||||
public class Email_settings {
|
||||
public static final String SMTP_HOST = "smtp.qq.com";
|
||||
// 邮箱服务器端口
|
||||
public static final String SMTP_PORT = "587";
|
||||
// 发件人邮箱
|
||||
public static final String FROM_EMAIL = "835981889@qq.com";
|
||||
// 发件人邮箱授权码
|
||||
public static final String EMAIL_PASSWORD = "fpqfprqznbvdbcdf";
|
||||
// 是否启用SSL
|
||||
public static final boolean SSL_ENABLE = true;
|
||||
private static final String CONFIG_FILE = "config/email.properties";
|
||||
private static Properties properties;
|
||||
private static long lastModified = 0;
|
||||
|
||||
static {
|
||||
loadConfig();
|
||||
}
|
||||
|
||||
private static void loadConfig() {
|
||||
properties = new Properties();
|
||||
setDefaultProperties();
|
||||
File configFile = new File(CONFIG_FILE);
|
||||
if (configFile.exists()) {
|
||||
try (FileInputStream input = new FileInputStream(configFile)) {
|
||||
properties.load(input);
|
||||
lastModified = configFile.lastModified();
|
||||
} catch (IOException e) {
|
||||
System.err.println("加载邮箱配置文件失败,使用默认配置: " + e.getMessage());
|
||||
}
|
||||
} else {
|
||||
createDefaultConfigFile();
|
||||
}
|
||||
}
|
||||
|
||||
private static void setDefaultProperties() {
|
||||
properties.setProperty("smtp.host", "smtp.qq.com");
|
||||
properties.setProperty("smtp.port", "587");
|
||||
properties.setProperty("from.email", "835981889@qq.com");
|
||||
properties.setProperty("email.password", "fpqfprqznbvdbcdf");
|
||||
properties.setProperty("ssl.enable", "true");
|
||||
}
|
||||
|
||||
private static void createDefaultConfigFile() {
|
||||
File configDir = new File("config");
|
||||
if (!configDir.exists()) {
|
||||
configDir.mkdirs();
|
||||
}
|
||||
|
||||
try (FileOutputStream output = new FileOutputStream(CONFIG_FILE)) {
|
||||
properties.store(output, "Settings");
|
||||
} catch (IOException e) {
|
||||
System.err.println("创建默认配置文件失败: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private static void checkForUpdates() {
|
||||
File configFile = new File(CONFIG_FILE);
|
||||
if (configFile.exists() && configFile.lastModified() > lastModified) {
|
||||
loadConfig();
|
||||
}
|
||||
}
|
||||
|
||||
public static String getSmtpHost() {
|
||||
checkForUpdates();
|
||||
return properties.getProperty("smtp.host");
|
||||
}
|
||||
|
||||
public static String getSmtpPort() {
|
||||
checkForUpdates();
|
||||
return properties.getProperty("smtp.port");
|
||||
}
|
||||
|
||||
public static String getFromEmail() {
|
||||
checkForUpdates();
|
||||
return properties.getProperty("from.email");
|
||||
}
|
||||
|
||||
public static String getEmailPassword() {
|
||||
checkForUpdates();
|
||||
return properties.getProperty("email.password");
|
||||
}
|
||||
|
||||
public static boolean isSslEnable() {
|
||||
checkForUpdates();
|
||||
return Boolean.parseBoolean(properties.getProperty("ssl.enable"));
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in new issue