WIP
This commit is contained in:
85
backend/tests/test-email-config.js
Normal file
85
backend/tests/test-email-config.js
Normal file
@ -0,0 +1,85 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
/**
|
||||
* Direct test of email service configuration
|
||||
*/
|
||||
|
||||
require('dotenv').config();
|
||||
const nodemailer = require('nodemailer');
|
||||
|
||||
async function testEmailConfig() {
|
||||
console.log('🔧 Testing Email Configuration...\n');
|
||||
|
||||
// Display current configuration
|
||||
console.log('Current Email Configuration:');
|
||||
console.log(`HOST: ${process.env.EMAIL_HOST}`);
|
||||
console.log(`PORT: ${process.env.EMAIL_PORT}`);
|
||||
console.log(`SECURE: ${process.env.EMAIL_SECURE}`);
|
||||
console.log(`USER: ${process.env.EMAIL_USER}`);
|
||||
console.log(`FROM: ${process.env.EMAIL_FROM}`);
|
||||
console.log(`PASSWORD: ${process.env.EMAIL_PASSWORD ? '[SET]' : '[NOT SET]'}\n`);
|
||||
|
||||
// Test configuration
|
||||
const config = {
|
||||
host: process.env.EMAIL_HOST,
|
||||
port: parseInt(process.env.EMAIL_PORT) || 587,
|
||||
secure: process.env.EMAIL_SECURE === 'true',
|
||||
auth: {
|
||||
user: process.env.EMAIL_USER,
|
||||
pass: process.env.EMAIL_PASSWORD
|
||||
}
|
||||
};
|
||||
|
||||
console.log('Parsed Configuration:');
|
||||
console.log(`Host: ${config.host}`);
|
||||
console.log(`Port: ${config.port}`);
|
||||
console.log(`Secure: ${config.secure}`);
|
||||
console.log(`Auth User: ${config.auth.user}`);
|
||||
console.log(`Auth Pass: ${config.auth.pass ? '[SET]' : '[NOT SET]'}\n`);
|
||||
|
||||
// Check required fields
|
||||
if (!config.host || !config.auth.user || !config.auth.pass) {
|
||||
console.error('❌ Missing required email configuration');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
console.log('🔍 Creating transporter...');
|
||||
const transporter = nodemailer.createTransport(config);
|
||||
|
||||
console.log('🔍 Verifying connection...');
|
||||
await transporter.verify();
|
||||
|
||||
console.log('✅ Email service configuration is valid!');
|
||||
|
||||
// Test sending a simple email
|
||||
console.log('📧 Testing email send...');
|
||||
const testEmail = {
|
||||
from: process.env.EMAIL_FROM || process.env.EMAIL_USER,
|
||||
to: process.env.EMAIL_USER, // Send to self for testing
|
||||
subject: 'Test Email - Bookmark Manager',
|
||||
text: 'This is a test email to verify the email service is working correctly.',
|
||||
html: '<p>This is a test email to verify the email service is working correctly.</p>'
|
||||
};
|
||||
|
||||
const result = await transporter.sendMail(testEmail);
|
||||
console.log('✅ Test email sent successfully!');
|
||||
console.log(`Message ID: ${result.messageId}`);
|
||||
|
||||
} catch (error) {
|
||||
console.error('❌ Email service error:', error.message);
|
||||
|
||||
// Provide specific troubleshooting advice
|
||||
if (error.message.includes('ENOTFOUND')) {
|
||||
console.log('💡 Suggestion: Check if EMAIL_HOST is correct');
|
||||
} else if (error.message.includes('ECONNREFUSED')) {
|
||||
console.log('💡 Suggestion: Check if EMAIL_PORT is correct');
|
||||
} else if (error.message.includes('Invalid login')) {
|
||||
console.log('💡 Suggestion: Check EMAIL_USER and EMAIL_PASSWORD');
|
||||
} else if (error.message.includes('SSL')) {
|
||||
console.log('💡 Suggestion: Try setting EMAIL_SECURE=false for port 587');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
testEmailConfig().catch(console.error);
|
||||
Reference in New Issue
Block a user