package com.mvc.utils;

import java.util.Properties;
import javax.mail.Authenticator;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;

public final class JavaMailUntil {
    private JavaMailUntil() {

    }

    public static Session createSession(String username,String password) {
        //	账号信息
        /*String username = "support@xzeai.com";  //	邮箱发送账号
        String password = "iLx7u44yqGSKJZQo";   //	邮箱授权码*/
        //	创建一个配置文件，并保存
        Properties props = new Properties();
        props.setProperty("mail.debug", "false");
        // 邮件服务器
        props.setProperty("mail.smtp.host", "smtp.exmail.qq.com");
        // 端口号
        props.setProperty("mail.smtp.port", "465");
        // 需要身份验证
        props.setProperty("mail.smtp.auth", "true");
        // 发送邮件协议
        props.setProperty("mail.transport.protocol", "smtp");
        props.setProperty("mail.smtp.ssl.enable", "true");

        Session session = Session.getInstance(props,new Authenticator() {
            @Override
            protected PasswordAuthentication getPasswordAuthentication() {
                // TODO Auto-generated method stub
                return new PasswordAuthentication(username,password);
            }
        });

        //  控制台打印调试信息
        session.setDebug(true);
        return session;
    }
}