require('dotenv').config();
const { sendEmail } = require('./services/email');

async function test() {
    console.log('Testing SMTP configuration...');
    console.log('Host:', process.env.SMTP_HOST);
    console.log('Port:', process.env.SMTP_PORT);
    console.log('User:', process.env.SMTP_USER);

    // Temporarily set NODE_ENV to production to test actual sending
    const originalEnv = process.env.NODE_ENV;
    process.env.NODE_ENV = 'production';

    try {
        await sendEmail(
            process.env.SMTP_USER,
            '<h1>SMTP Test Successful</h1><p>Your Elfit Arabia B2B portal is now configured to use Nodemailer.</p>',
            'Elfit Arabia SMTP Test'
        );
        console.log('Test email sent successfully! Please check your inbox.');
    } catch (error) {
        console.error('Test failed:', error.message);
    } finally {
        process.env.NODE_ENV = originalEnv;
    }
}

test();
