IMAP trigger node returns message UIDs

IMAP trigger node returns message UIDs

Hello.
How to get UID email in IMAP node? Here https://github.com/n8n-io/n8n/pull/13152 they write that you can do this. But I don’t understand how to do this? I don’t have an attributes column with UID data.

Information on your n8n setup

  • **n8n version: 1.80.3
  • Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • **Running n8n via (Docker, npm, n8n cloud, desktop app): Docker
  • **Operating system: Ubuntu 22.04

hello @koordinator7

The PR is not yet implemented. It’s still open

Thanks for the answer @ barn4k. What is PR? And how to find out when it will be done. In the screenshot there is already a UID.

It will be done once it will be done :slight_smile:

Maybe you can manually register the changes? I just don’t understand where to register.

The feature you’re looking for (email UIDs in IMAP trigger) isn’t released yet - the pull request (#13152) is still open and pending merge.

As a workaround (VERY HARD) until this is officially implemented:

  1. Add a Function node after your IMAP trigger with this code:

    // This extracts message IDs which can be used for tracking
    return items.map(item => {
      const headers = item.json.headers;
      return {
        ...item.json,
        trackingId: headers['message-id'] || 
                   headers['Message-ID'] || 
                   `${headers.Date}_${headers.From}`.replace(/[<>]/g, '')
      }
    });
    
  2. Alternatively, if you really need UIDs specifically, you can create a custom IMAP connection using the Function node:

    const imapSimple = require('imap-simple');
    const config = {
      imap: {
        user: 'your_email',
        password: 'your_password',
        host: 'imap.example.com',
        port: 993,
        tls: true
      }
    };
    
    // This is a simplified example - you'd need to implement full email retrieval
    const messages = await imapSimple.connect(config).then(connection => {
      return connection.search(['UNSEEN'], {bodies: ['HEADER', 'TEXT']})
    });
    
    // Each message will have a uid property
    return {json: {messages}};
    

Note: Manual code modifications to n8n core are not recommended as they’ll be overwritten on updates.

Thank you.
Do I understand correctly that UID and Message-ID are different things? I need UID. The option with “Add a Function node after your IMAP trigger with this code:” did not work for me, it gives an error. If you can, please send me the working process.