MS365
Microsoft 365 and Outlook.com are reached through Microsoft Graph. No mail program needs to run, and it works with the new Outlook too. For the most common case, sending a mail with attachments, there is also the ready-made Outlook365 action.
Once: create the connector
Section titled “Once: create the connector”- Open Connectors, click New and choose the Microsoft Outlook Mail template (for contacts: Outlook Contacts).
- Name the connector
OutlookMail(orOutlookContacts) and save. - Click Sign in with browser, sign in with the mailbox and confirm the permissions.
The status then shows Ready. RUNOS renews the sign-in itself. More under OAuth2.
Send a mail
Section titled “Send a mail”{ "Type": "HttpRequest", "Name": "SendMail", "Parameters": { "Url": "https://graph.microsoft.com/v1.0/me/sendMail", "Method": "POST", "Connector": "OutlookMail", "BodyType": "json", "Body": { "message": { "subject": "Your document {{FileName}}", "body": { "contentType": "Text", "content": "Hello,\n\nplease find your document attached." }, "toRecipients": [ { "emailAddress": { "address": "customer@example.com" } } ], "attachments": [ { "@odata.type": "#microsoft.graph.fileAttachment", "name": "{{FileName}}", "contentBytes": "{{FilePath.toBase64()}}" } ] }, "saveToSentItems": true } }}{{FilePath.toBase64()}}reads the file and returns its content as Base64, as Graph expects for attachments.- Graph answers with
StatusCode202and an emptyBody; the mail is then in Sent Items. - This way, requests of up to about 4 MB are possible. For larger attachments use the Outlook365 action; it uploads files of up to 150 MB in parts.
Read contacts
Section titled “Read contacts”{ "Type": "HttpRequest", "Name": "Contacts", "Parameters": { "Url": "https://graph.microsoft.com/v1.0/me/contacts?$select=displayName,emailAddresses,companyName&$top=100", "Connector": "OutlookContacts", "AutoPagination": true }}With AutoPagination RUNOS follows Graph’s @odata.nextLink until all pages are read; every page is an entry in Response.Results. The contacts of all pages are together in {{Contacts.Response.Items}} and can be iterated with a Loop:
{ "Type": "Loop", "Name": "EachContact", "Parameters": { "Items": "{{Contacts.Response.Items}}", "Do": [ { "Type": "SMTP", "Name": "Write", "Parameters": { "To": "{{item.emailAddresses.0.address}}", "Subject": "Hello {{item.displayName}}", "Body": "…" } } ] }}The Outlook365 action
Section titled “The Outlook365 action”The Outlook365 action sends mails through the same connector without you writing the Graph JSON. It uploads large attachments in parts and can create drafts.
{ "Type": "Outlook365", "Name": "MailInvoice", "Parameters": { "Connector": "OutlookMail", "Mode": "Send", "To": "{{InitialData.Recipient}}", "Subject": "Invoice {{InitialData.Invoice.BT1}}", "Body": "Hello,\n\nplease find your invoice attached.", "Attachments": "{{FilePath}}" }}| Parameter | Default | Meaning |
|---|---|---|
Connector |
OutlookMail |
Name of the Microsoft connector |
Mode |
Send |
Send sends; Draft saves in the Drafts folder; Display saves a draft and opens it in Outlook on the web |
From |
– | Empty: the signed-in mailbox. Otherwise a shared mailbox or one with “Send as” rights. |
To, Cc, Bcc, ReplyTo |
– | Recipients separated by ; or ,. Name <a@b.com>, lists and files with addresses are allowed. |
Subject |
– | Subject |
Body, Signatur |
– | Text or path of a text or HTML file |
BodyFormat |
Auto |
Auto, Html or Text |
Attachments |
– | Path, several separated by ;, a list or a pattern such as C:\Out\*.pdf. Up to 150 MB per file. |
MissingAttachments |
Error |
Error or Skip |
Importance |
Normal |
Low, Normal, High |
ReadReceipt, DeliveryReceipt |
false |
Request receipts |
SaveToSentItems |
true |
Copy in Sent Items. With large attachments it always stays there. |
Timeout |
100 |
Time limit per request to Microsoft in seconds |
The result contains per mail Mode, Status (e.g. Sent), From, To, Subject, Attachments and Message; with Draft and Display also MessageId and WebLink to the draft.
| Message | Fix |
|---|---|
| No connector named “…” | Create the connector or correct the name in Connector |
| … is not signed in | Click Sign in with browser on the Connectors page |
Error 403 with From |
“Send as” rights for the mailbox are missing |
In the diagram of the workflow editor the action has a form: Account lists the saved connectors (the button next to it reads them again), and you choose Mode with the Send directly, Save as draft and Open to check buttons; then To, Cc, Bcc, Subject, Text, Signature and Attachments (up to 150 MB per file). More options has From (empty = the signed-in mailbox, otherwise e.g. a shared mailbox), reply-to, body format, importance, missing attachments (error or skip), read and delivery receipts, Keep in Sent Items (on by default) and the time limit (default 100 seconds). Every field also takes {{…}} placeholders and values you drag in from the Input column of the test view; lists, switches and number fields become a text field when given a {{…}}. Parameters the form does not know are kept under Other parameters. Test step runs the action once, right away, with the data of the earlier steps, and shows the result with errors and warnings. The test really sends or saves the mail.
The workflow template Mail über Microsoft 365 (under New) contains a ready example.
