Email Monitor Trigger icon

Email Monitor Trigger

Triggers when new emails are received

Overview

This node is an Email Monitor Trigger that connects to an IMAP email server and triggers when new emails are received. It periodically polls the mailbox at a user-defined interval, applies various filters to incoming emails, and outputs matching emails as JSON objects. This node is useful for automating workflows based on incoming emails, such as processing support requests, monitoring notifications, or triggering actions from specific senders or subjects.

Practical examples:

  • Automatically trigger a workflow when an unread email arrives from a particular sender.
  • Process only emails received after a certain date.
  • Filter emails by subject content, including support for Chinese characters.
  • Mark processed emails as read to avoid reprocessing.

Properties

Name Meaning
Poll Interval How often to check for new emails (in seconds). Minimum value is 10 seconds.
Filter Options Collection of filters to apply when searching for emails:
- From Filter emails by sender email address.
- Mark as Read Whether to mark processed emails as read after fetching them (true/false).
- Only Unread Whether to only check unread emails (true/false).
- Since Date Only fetch emails received after this date/time.
- Subject Contains Filter emails by text contained in the subject line. Supports Chinese characters; if detected, filtering is done client-side rather than via IMAP search.

Output

The node outputs an array of JSON objects, each representing an email that matches the filter criteria. Each email object contains the following fields:

  • seqno: Sequence number of the email in the mailbox.
  • uid: Unique identifier of the email.
  • subject: Subject line of the email.
  • from: Sender's email address (text format).
  • to: Recipient(s) email addresses (text format).
  • date: Date the email was sent.
  • text: Plain text body of the email.
  • html: HTML body of the email.
  • attachments: Array of attachments included in the email.
  • flags: Array of flags set on the email (e.g., seen/unseen).

If the "Mark as Read" option is enabled, the node will mark the fetched emails as read on the server after processing.

Dependencies

  • Requires connection credentials to an IMAP email server, including host, port, username, password, and security settings.
  • Uses the imap library to connect and interact with the IMAP server.
  • Uses the mailparser library to parse raw email data into structured format.
  • The node requires appropriate API authentication credentials configured in n8n to access the email account.

Troubleshooting

  • Connection errors: If the node cannot connect to the IMAP server, verify the host, port, username, password, and TLS settings. Ensure network connectivity and that the email server supports IMAP.
  • No emails found: Check filter settings such as "Only Unread," "From," "Since Date," and "Subject Contains." Filters may be too restrictive or incorrectly specified.
  • Error parsing emails: Malformed emails or unsupported formats might cause parsing errors. These are logged but do not stop processing other emails.
  • Mark as Read not working: Ensure the email account allows flag modifications and that the node has sufficient permissions.
  • Chinese characters in subject: When filtering by subject containing Chinese characters, filtering is done client-side after fetching emails because IMAP search does not support these characters well. This may impact performance if many emails are fetched.

Links and References

Discussion