package com.storlead.sales;

import javax.mail.*;
import java.util.Properties;

public class Main {
    public static void main(String[] args) {

        // 设置邮件服务器的属性
        Properties properties = new Properties();
        properties.put("mail.pop3.host", "pop3.example.com");
        properties.put("mail.pop3.port", "995");
        properties.put("mail.pop3.starttls.enable", "true");

        // 验证收件人的邮箱和密码
        Authenticator auth = new Authenticator() {
            protected PasswordAuthentication getPasswordAuthentication() {
                return new PasswordAuthentication("earvin@storlead.com", "Wynah04270927!");
            }
        };

        // 创建邮件会话
        Session session = Session.getInstance(properties, auth);

        try {
            // 连接到邮件服务器
            Store store = session.getStore("pop3");
            store.connect();

            // 打开收件箱
            Folder inbox = store.getFolder("INBOX");
            inbox.open(Folder.READ_ONLY);

            // 获取邮件列表
            Message[] messages = inbox.getMessages();

            // 遍历邮件并打印主题
            for (int i = 0; i < messages.length; i++) {
                System.out.println("邮件 " + (i + 1) + ": " + messages[i].getSubject());
            }

            // 关闭收件箱和邮件服务器连接
            inbox.close(false);
            store.close();

        } catch (NoSuchProviderException e) {
            e.printStackTrace();
        } catch (MessagingException e) {
            e.printStackTrace();
        }
    }
}