Hi, I have couple of email boxes from zoho and other using function node with login and password.
App password used
Host: imap.zoho.com
port:993
IMAP/SMTP check box Yes
n8n is not able to access ZOHO inbox with function node.
Any suggestion or solution for this problem.
thanks
const imaps = require(‘imap-simple’);
const config = {
imap: {
user: ‘YOUR_FULL_EMAIL@zoho.com’,
password: ‘YOUR_16_CHAR_APP_PASSWORD’, // No spaces
host: ‘imap.zoho.com’,
port: 993,
tls: true,
authTimeout: 10000,
tlsOptions: {
servername: ‘imap.zoho.com’,
rejectUnauthorized: true
}
}
};
try {
// Pass ‘config’ directly here
const connection = await imaps.connect(config);
await connection.openBox('INBOX');
// Always close the connection
connection.end();
return [{ json: { success: true } }];
} catch (err) {
return [{ json: { success: false, error: err.message } }];
}
Describe the problem/error/question
What is the error message (if any)?
Please share your workflow
(Select the nodes on your canvas and use the keyboard shortcuts CMD+C/CTRL+C and CMD+V/CTRL+V to copy and paste the workflow.)
Share the output returned by the last node
Information on your n8n setup
- n8n version:
- Database (default: SQLite):
- n8n EXECUTIONS_PROCESS setting (default: own, main):
- Running n8n via (Docker, npm, n8n cloud, desktop app):
- Operating system:
Hi @ITteck_hub , welcome back !
Two issues here:
-
require('imap-simple') won’t work in the Code node by default. External npm packages are blocked in the sandbox unless you set the NODE_FUNCTION_ALLOW_EXTERNAL environment variable and install the package in your n8n instance. That’s a lot of overhead for something n8n handles natively.
-
Use the Email Trigger (IMAP) node instead. Set up the IMAP credentials with:
The trigger polls for new emails automatically on its own interval, so you don’t need a separate Schedule Trigger.
Is there a specific reason you need the Code node approach over the built-in trigger?
Yes, already done ODE_FUNCTION_ALLOW_EXTERNAL.
Email trigger IMAP does not have flexibility of handling multiple Inbox/user ids.
Any other options?
good day @ITteck_hub
I’d normally create one IMAP Email Trigger credential per mailbox, or split the polling into separate workflows. If you need dynamic mailbox polling from a list of users, a safer option is to run a small external IMAP service/script and let n8n call it with HTTP, instead of managing many IMAP sessions and credentials inside a Code node.Also double-check Zoho’s side, IMAP enabled for the mailbox, app password valid, correct account region/host, and no IP/security restriction blocking your n8n server.
For multiple mailboxes dynamically, one pattern that works: store your mailbox list (user, app_password, host) in a Google Sheet or database, then use a Schedule trigger + loop to iterate over each row. Inside the loop, the Code node uses imap-simple (with N8N_FUNCTION_ALLOW_EXTERNAL already set) and opens a fresh connection per mailbox using the credentials from that row. Each connection is created and closed within the same iteration, so you avoid session overlap issues. If Zoho’s IMAP is still failing per-mailbox, also check that each account has IMAP explicitly enabled in Zoho Mail settings - Zoho sometimes requires it per-mailbox even with an org-level app password.
Email IMAP trigger is working.. I think will try fetching email id/pw/host details from DB instead of setting up in function file.
on zoho email server or n8n vps?