package com.storlead.sales.mail.connection.client;

import com.storlead.sales.mail.connection.MailConnectionFactory;
import com.storlead.sales.mail.connection.SMTPConnection;
import com.storlead.sales.mail.connection.SMTPConnectionFactory;

import javax.mail.MessagingException;

/**
 * @program: sp-sales-platform
 * @description:
 * @author: chenkq
 * @create: 2024-05-30 16:34
 */
public class MailSenderUtil {
    public static void sendEmail(String host, String port, String user, String password,
                                 String toAddress, String subject, String messageContent) {
        SMTPConnectionFactory smtpFactory = MailConnectionFactory.getSMTPFactory(host, port, user, password);
        SMTPConnection smtpConnection = smtpFactory.createConnection();
        try {
            smtpConnection.connect();
            smtpConnection.sendEmail(toAddress, subject, messageContent);
        } catch (MessagingException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        String smtpHost = "smtp.exmail.qq.com";
        String smtpPort = "465";
        String user = "your_email@example.com"; // Replace with your email
        String password = "your_password"; // Replace with your password

        System.out.println("Sending email using SMTP:");
        sendEmail(smtpHost, smtpPort, user, password,
                "recipient@example.com", "Test Subject", "Test Message");
    }
}
