package org.xyzh.message.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.JavaMailSenderImpl;

import java.util.Properties;

/**
 * @description 邮件发送器配置 - 手动创建JavaMailSender bean
 * @filename MailSenderConfig.java
 * @author yslg
 * @copyright xyzh
 * @since 2025-12-05
 */
@Configuration
public class MailSenderConfig {
    
    /**
     * 创建JavaMailSender bean
     * 初始值为默认配置，实际配置将在DynamicConfigLoader中从数据库加载
     */
    @Bean
    public JavaMailSender javaMailSender() {
        JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
        
        // 设置默认配置（防止未配置时报错）
        mailSender.setHost("smtp.example.com");
        mailSender.setPort(587);
        mailSender.setUsername("default");
        mailSender.setPassword("default");
        
        // 设置邮件属性
        Properties props = mailSender.getJavaMailProperties();
        props.put("mail.smtp.auth", "true");
        props.put("mail.smtp.starttls.enable", "true");
        props.put("mail.smtp.starttls.required", "false");
        props.put("mail.smtp.timeout", "30000");
        props.put("mail.smtp.connectiontimeout", "30000");
        
        return mailSender;
    }
}
