Listing Emails from an Outlook Folder by Date with the io.Connect Outlook Adapter

The io.Connect Outlook Adapter exposes an interop method, T42.Outlook.AdvancedSearch. A common use case is listing all emails received in a monitored folder for a given period, for example, when an app starts or restarts and needs to pull in everything received earlier the same day. You can register an interop callback, build a filter string, and invoke T42.Outlook.AdvancedSearch. The adapter delivers the search updates to your callback:

1. Register a callback to receive search updates

io.interop.register('onOutlookSearch', console.info)

2. Define a filter by date received

The example below filters to messages received between the start of today and the current time. It uses the urn:schemas:httpmail:datereceived property:

filter = `"urn:schemas:httpmail:datereceived" >= '${new Date(new Date().setHours(0,0,0,0)).toISOString().slice(0,19).replace("T"," ")}' AND "urn:schemas:httpmail:datereceived" <= '${new Date().toISOString().slice(0,19).replace("T"," ")}'`;

If you’d rather avoid inline date, here’s a helper to format a Date into the string format Outlook expects:

function toOutlookDateTimeString(date) {
  const pad = n => n.toString().padStart(2, "0");
  return (
    date.getFullYear() + "-" +
    pad(date.getMonth() + 1) + "-" +
    pad(date.getDate()) + " " +
    pad(date.getHours()) + ":" +
    pad(date.getMinutes()) + ":" +
    pad(date.getSeconds())
  );
}

3. Invoke the search

io.interop.invoke("T42.Outlook.AdvancedSearch", {
  itemType: "Mail",
  searchId: "today-mails-or-some-correlation-id",
  scope: "Inbox",
  filter,
  searchSubfolders: false,
  callbackMethod: "onOutlookSearch"
});


Additionally the method T42.Outlook.GetRootMonitorDetails, exposes information about the root monitor’s details.

See also