Skip to content

Outlook 365 Mail Activities

Version: 1.0.5  ·  ID: zoan-packages-outlook365  ·  Author: Zoan Software

The Outlook 365 package sends, searches, reads and organizes email in a Microsoft 365 mailbox through Microsoft Graph, using Zoan Cloud OAuth2 connections. It is the cloud counterpart of the desktop Outlook package: it needs neither Outlook installed nor an open Windows session, so it works the same in attended and unattended robots.

Concept 1: the connection and its permissions

Section titled “Concept 1: the connection and its permissions”

The activities use a Zoan Cloud Microsoft 365 OAuth connection, referenced by its key name in Connect (credential = credential("m365-support")). Zoan Cloud stores and renews the token; the robot never sees the account password.

Microsoft Graph permissionUsed for
Mail.ReadWriteSearching, reading, downloading attachments, moving, marking, categorizing and deleting.
Mail.SendSending, replying and forwarding.
Mail.ReadWrite.Shared / Mail.Send.SharedThe same on shared mailboxes, with delegated access.

The authentication type (delegated or app-only) is defined by the connection. With delegated access and no mailbox, the activities work on the mailbox of the user who authorized the connection; for shared mailboxes or app-only access, set mailbox in Connect.

Connect opens a session (ZoanOutlookMailSession) on a mailbox:

  • With body: the activities inside inherit it, and it closes by itself when they finish.
  • Without body: store it in a variable, pass it through session and close it with Close.

The session uses the token that was valid when it connected, which lasts about one hour: in long processes, work in batches and connect once per batch.

Get emails, Get email by ID and Move return each email as a Dictionary<string,object> with the keys id, subject, from, fromName, to, cc, receivedDateTime, preview, isRead, hasAttachments, categories, webLink, body and bodyType (details in Get emails). Read each value by key: email["subject"].

The id is the input of every other activity. It changes when the email is moved to another folder: do your work on the email before moving it, or use the id returned by Move.

ActivityTypeOutputDescription
Outlook 365 — Connectoutlook365-connectZoanOutlookMailSessionOpens an authenticated Outlook 365 session through Microsoft Graph
Outlook 365 — Sendoutlook365-send—Sends an email from the session’s mailbox
Outlook 365 — Replyoutlook365-reply—Replies to an existing email, keeping the thread
Outlook 365 — Forwardoutlook365-forward—Forwards an email to other recipients
Outlook 365 — Get emailsoutlook365-get-emailsList<Dictionary<string,object>>Searches the mailbox or a folder by subject, text, filter or unread status
Outlook 365 — Get email by IDoutlook365-get-emailDictionary<string,object>Gets a full email by its ID, including the body
Outlook 365 — Download attachmentsoutlook365-download-attachmentsList<string>Downloads an email’s attachments to a folder
Outlook 365 — Moveoutlook365-moveDictionary<string,object>Moves an email to another folder
Outlook 365 — Mark read/unreadoutlook365-mark-read—Marks an email as read or unread
Outlook 365 — Set categoriesoutlook365-set-categories—Sets an email’s categories (replacing the existing ones)
Outlook 365 — Deleteoutlook365-delete—Deletes an email
Outlook 365 — Closeoutlook365-close—Closes an Outlook 365 session
Outlook 365 — Connect credential = credential("m365-invoices")
└─ body:
Outlook 365 — Get emails folder = "inbox" subject = "Invoice" unreadOnly = true → output: pending
For each email in pending
└─ Outlook 365 — Download attachments id = email["id"] folder = "C:\invoices\inbox"
Outlook 365 — Reply id = email["id"] body = "We received your invoice and will record it in the next few days."
Outlook 365 — Move id = email["id"] destination = "archive"