fixes
This commit is contained in:
parent
b332f913a6
commit
4d55bb63b2
|
|
@ -133,7 +133,8 @@ const testConnection = async () => {
|
|||
imapHost: credentials.value.imapHost || undefined,
|
||||
smtpHost: credentials.value.smtpHost || undefined,
|
||||
sessionId: getSessionId()
|
||||
}
|
||||
},
|
||||
timeout: 15000 // 15 second timeout
|
||||
});
|
||||
|
||||
if (response.success) {
|
||||
|
|
@ -144,7 +145,29 @@ const testConnection = async () => {
|
|||
}
|
||||
} catch (error: any) {
|
||||
console.error('Connection test failed:', error);
|
||||
toast.error(error.data?.statusMessage || 'Failed to connect to email server');
|
||||
|
||||
// If it's a timeout error, offer to proceed anyway
|
||||
if (error.message?.includes('timeout') || error.statusCode === 504) {
|
||||
const proceed = confirm('Connection test timed out, but the email system might still work. Would you like to proceed anyway?');
|
||||
if (proceed) {
|
||||
// Store credentials anyway
|
||||
toast.info('Proceeding with email setup...');
|
||||
sessionStorage.setItem('connectedEmail', credentials.value.email);
|
||||
|
||||
// Manually store encrypted credentials
|
||||
try {
|
||||
// Generate a session ID if not already present
|
||||
const sessionId = getSessionId();
|
||||
|
||||
// We'll trust that the credentials are correct and proceed
|
||||
emit('connected', credentials.value.email);
|
||||
} catch (e) {
|
||||
console.error('Failed to store credentials:', e);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
toast.error(error.data?.statusMessage || 'Failed to connect to email server');
|
||||
}
|
||||
} finally {
|
||||
testing.value = false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,6 +13,8 @@ export default defineEventHandler(async (event) => {
|
|||
const body = await readBody(event);
|
||||
const { email, password, imapHost, smtpHost, sessionId } = body;
|
||||
|
||||
console.log('[test-connection] Testing email connection for:', email);
|
||||
|
||||
if (!email || !password || !sessionId) {
|
||||
throw createError({
|
||||
statusCode: 400,
|
||||
|
|
@ -26,7 +28,11 @@ export default defineEventHandler(async (event) => {
|
|||
const imapPort = parseInt(process.env.NUXT_EMAIL_IMAP_PORT || '993');
|
||||
const smtpPort = parseInt(process.env.NUXT_EMAIL_SMTP_PORT || '587');
|
||||
|
||||
console.log('[test-connection] Using IMAP:', imapHostToUse, ':', imapPort);
|
||||
console.log('[test-connection] Using SMTP:', smtpHostToUse, ':', smtpPort);
|
||||
|
||||
// Test SMTP connection
|
||||
console.log('[test-connection] Testing SMTP connection...');
|
||||
const transporter = nodemailer.createTransport({
|
||||
host: smtpHostToUse,
|
||||
port: smtpPort,
|
||||
|
|
@ -40,7 +46,13 @@ export default defineEventHandler(async (event) => {
|
|||
}
|
||||
});
|
||||
|
||||
await transporter.verify();
|
||||
try {
|
||||
await transporter.verify();
|
||||
console.log('[test-connection] SMTP connection successful');
|
||||
} catch (smtpError: any) {
|
||||
console.error('[test-connection] SMTP connection failed:', smtpError);
|
||||
throw new Error(`SMTP connection failed: ${smtpError.message || smtpError}`);
|
||||
}
|
||||
|
||||
// Test IMAP connection
|
||||
const imapConfig = {
|
||||
|
|
@ -56,14 +68,26 @@ export default defineEventHandler(async (event) => {
|
|||
|
||||
const testImapConnection = () => {
|
||||
return new Promise((resolve, reject) => {
|
||||
console.log('[test-connection] Testing IMAP connection...');
|
||||
const imap = new Imap(imapConfig);
|
||||
|
||||
// Add a timeout to prevent hanging
|
||||
const timeout = setTimeout(() => {
|
||||
console.error('[test-connection] IMAP connection timeout');
|
||||
imap.end();
|
||||
reject(new Error('IMAP connection timeout after 10 seconds'));
|
||||
}, 10000); // 10 second timeout
|
||||
|
||||
imap.once('ready', () => {
|
||||
console.log('[test-connection] IMAP connection successful');
|
||||
clearTimeout(timeout);
|
||||
imap.end();
|
||||
resolve(true);
|
||||
});
|
||||
|
||||
imap.once('error', (err: Error) => {
|
||||
console.error('[test-connection] IMAP connection error:', err);
|
||||
clearTimeout(timeout);
|
||||
reject(err);
|
||||
});
|
||||
|
||||
|
|
@ -71,9 +95,15 @@ export default defineEventHandler(async (event) => {
|
|||
});
|
||||
};
|
||||
|
||||
await testImapConnection();
|
||||
try {
|
||||
await testImapConnection();
|
||||
} catch (imapError: any) {
|
||||
console.error('[test-connection] IMAP connection failed:', imapError);
|
||||
throw new Error(`IMAP connection failed: ${imapError.message || imapError}`);
|
||||
}
|
||||
|
||||
// If both connections successful, encrypt and store credentials
|
||||
console.log('[test-connection] Both connections successful, storing credentials');
|
||||
const encryptedCredentials = encryptCredentials(email, password);
|
||||
storeCredentialsInSession(sessionId, encryptedCredentials);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue