Skip to main content

IMAP Listener

Listen for mails received in one mailbox accesible using the IMAP protocol.

Tagsemailimap

Credential configuration

To configure this credential, you need to fill the credential configuration form with the IMAP connection parameters: hostname, port, username, password and tls configuration.

Additionally to the connection information, you'll need to fill the mailbox related information:

  • mailbox: name of the mailbox you want to listen.
  • searchFilters configuration (optional), to be used in node-imap package:
    • The following message flags are valid types that do not have arguments:
      • 'ALL' - All messages.
      • 'ANSWERED' - Messages with the Answered flag set.
      • 'DELETED' - Messages with the Deleted flag set.
      • 'DRAFT' - Messages with the Draft flag set.
      • 'FLAGGED' - Messages with the Flagged flag set.
      • 'NEW' - Messages that have the Recent flag set but not the Seen flag.
      • 'SEEN' - Messages that have the Seen flag set.
      • 'RECENT' - Messages that have the Recent flag set.
      • 'OLD' - Messages that do not have the Recent flag set. This is functionally equivalent to "!RECENT" (as opposed to "!NEW").
      • 'UNANSWERED' - Messages that do not have the Answered flag set.
      • 'UNDELETED' - Messages that do not have the Deleted flag set.
      • 'UNDRAFT' - Messages that do not have the Draft flag set.
      • 'UNFLAGGED' - Messages that do not have the Flagged flag set.
      • 'UNSEEN' - Messages that do not have the Seen flag set.
    • The following are valid types that require string value(s):
      • 'BCC' - Messages that contain the specified string in the BCC field.
      • 'CC' - Messages that contain the specified string in the CC field.
      • 'FROM' - Messages that contain the specified string in the FROM field.
      • 'SUBJECT' - Messages that contain the specified string in the SUBJECT field.
      • 'TO' - Messages that contain the specified string in the TO field.
      • 'BODY' - Messages that contain the specified string in the message body.
      • 'TEXT' - Messages that contain the specified string in the header OR the message body.
      • 'KEYWORD' - Messages with the specified keyword set.
      • 'HEADER' - Requires two string values, with the first being the header name and the second being the value to search for. If this second string is empty, all messages that contain the given header name will be returned.
    • The following are valid types that require a string parseable by JavaScript's Date object OR a Date instance:
      • 'BEFORE' - Messages whose internal date (disregarding time and timezone) is earlier than the specified date.
      • 'ON' - Messages whose internal date (disregarding time and timezone) is within the specified date.
      • 'SINCE' - Messages whose internal date (disregarding time and timezone) is within or later than the specified date.
      • 'SENTBEFORE' - Messages whose Date header (disregarding time and timezone) is earlier than the specified date.
      • 'SENTON' - Messages whose Date header (disregarding time and timezone) is within the specified date.
      • 'SENTSINCE' - Messages whose Date header (disregarding time and timezone) is within or later than the specified date.
    • The following are valid types that require one Integer value:
      • 'LARGER' - Messages with a size larger than the specified number of bytes.
      • 'SMALLER' - Messages with a size smaller than the specified number of bytes.
  • markSeen: set to true to mark the messages as read.
  • fetchUnreadOnStart: set to true to fetch unread messages on start.

Here is an example of a filled credential configuration form in YepCode:

IMAP Snippets available in editor

note

The title is the triggering text for YepCode to autocomplete the script.

Listener

New listener
const mailListener = await yepcode.listener.imap("your-mailbox");

mailListener.start((mail) => {
console.log(`New mail message received`, mail);
const { messageId, from, to, date, subject, body } = mail;
const { text, html } = body;
});