package com.mathgenerator.service; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.util.Properties; public class EmailConfig { private static final Properties properties = new Properties(); static { try (InputStream input = new FileInputStream("config.properties")) { properties.load(input); } catch (IOException ex) { System.err.println("错误:无法加载 config.properties 文件!请确保该文件在项目根目录中。"); ex.printStackTrace(); } } public static String getHost() { return properties.getProperty("smtp.host"); } public static int getPort() { return Integer.parseInt(properties.getProperty("smtp.port")); } public static String getUsername() { return properties.getProperty("smtp.username"); } public static String getPassword() { return properties.getProperty("smtp.password"); } }