// Simple email test
import nodemailer from "nodemailer";

async function testSimpleEmail() {
  console.log("🧪 Testing simple email...\n");

  try {
    // Create transporter
    const transporter = nodemailer.createTransport({
      host: "smtp.gmail.com",
      port: 587,
      secure: false,
      auth: {
        user:"developer0031@gmail.com",
        pass: "fkck glbf gcjo qheg", // ⚠️ REPLACE with 16-character app password from Google
      },
    });

    console.log("✅ Transporter created");

    // Verify connection
    console.log("🔍 Verifying SMTP connection...");
    await transporter.verify();
    console.log("✅ SMTP connection verified");

    // Send test email
    const testEmail = process.argv[2] || "developer0031@gmail.com";
    console.log("📧 Sending email to:", testEmail);

    const info = await transporter.sendMail({
      from: "Cssawwwards@gmail.com",
      to: testEmail,
      subject: "Test Email from CSSA",
      html: "<h1>Test Email</h1><p>If you receive this, email is working!</p>",
    });

    console.log("✅ Email sent successfully!");
    console.log("📧 Message ID:", info.messageId);
    console.log("📨 Response:", info.response);
  } catch (error) {
    console.error("❌ Error:", error.message);
    console.error("Code:", error.code);
    
    if (error.code === "EAUTH") {
      console.log("\n⚠️  Authentication failed!");
      console.log("The app password may be invalid or expired.");
    }
  }
}

testSimpleEmail();
