Skip to content

Outlook Get Emails

Type: outlook-get-emails  ·  Package: Outlook Activities v1.0.4  ·  Output: List<ZoanMail>

Reads the emails of an Outlook folder and returns a list of messages (ZoanMail). It is the starting point of almost every mail-based process: read what arrived, loop over it and act on each message.

  1. Resolves the folder (default Inbox). It accepts English aliases (inbox, sent, drafts, deleted, junk, outbox), the name Outlook shows in your language and paths with / — see Folders.
  2. Sorts the items from newest to oldest (by received date).
  3. Applies the filter: if you set filter, that one is used; otherwise, with unreadOnly = true, only unread items are taken.
  4. Returns up to maxCount emails. Meeting requests, read receipts and other items that are not emails are skipped and do not count towards the maximum.

Reading does not change the emails: they stay unread until you use Outlook Mark Read. Without session, the default account is used.

None.

ParameterTypeDefaultDescription
sessionZoanOutlookSession—Session from Outlook Connect. Inherited inside the Connect body; without a session the default account is used.
folderstring"Inbox"Folder to read. Alias, localized name or path with / for subfolders: "Inbox/Customers".
maxCountint50Maximum number of emails to return. A value that is not a whole number is treated as 50.
unreadOnlyboolfalseReturn only unread emails. Ignored when you set filter (add it to the filter instead: [UnRead] = True).
filterstring—Outlook filter applied to the folder items. Outlook syntax ("[Subject] = 'Invoice'", "[UnRead] = True AND [SenderEmailAddress] = 'vendor@company.com'") or DASL with the @SQL= prefix for content searches.

Returns a List<ZoanMail> sorted from newest to oldest. Each email has .Id (EntryID), .Subject, .From, .To, .Cc, .Body (plain text), .SentAt (received date) and .IsRead; .Attachments and .Bcc are empty. Details in What each email contains.

If no email matches, it returns an empty list (not an error): check it with count(emails) == 0.

MessageCause and fix
Folder not found at level {0} of the path (under {1}). {2}A segment of folder does not exist. The message gives the level and how many subfolders there are; check the spelling or use the name Outlook shows.
Outlook did not return its default folder. Check that Outlook is installed, has a configured mail profile, and runs at the same elevation level as the robot (…)There is no usable mail profile, or the robot and Outlook run at different elevation levels. Configure the profile and run both at the same level.
COM component 'Outlook.Application' is not registered. Is the application installed?Outlook is not installed on the robot’s machine.
Outlook error when parsing the conditionfilter has invalid syntax (quotes, property name). Test the filter with a fixed value before building it with expressions.

Read the unread emails of the inbox, save their attachments and mark them as read:

Outlook Get Emails folder = "Inbox" unreadOnly = true maxCount = 20 → output: emails
For Each items = emails itemVariable = email
└─ activities:
Log message = "From: " + email.From + " — " + email.Subject
Outlook Get Attachments entryId = email.Id outputDir = "C:/invoices" → output: files
Outlook Mark Read entryId = email.Id

Useful filters (what you type in the filter field):

[Subject] = 'Invoice 1043' exact subject
[UnRead] = True AND [SenderEmailAddress] = 'vendor@company.com'
@SQL="urn:schemas:httpmail:subject" LIKE '%Invoice%' subject containing «Invoice»