Office 365 Outlook

If you connect to Office 365 Outlook, you can show, send, delete, and reply to email messages, in addition to other tasks.

You can add controls, including buttons and text boxes, to do these functions in your app. For example, you can add input text boxes on your app that asks for email information, including the recipient, the subject, and the body of the email. Then, add a Send button that sends the email.

This topic shows you how to add Office 365 Outlook as a connection, add Office 365 Outlook as a data source to your app, and use this data in different controls.

Important: As of this writing, the functions for calendar and contacts aren't supported.

 

What you need to get started

Connect to Office 365

  1. Add a data connection and select Office 365 Outlook:

    Connect to Office 365

  2. Select Connect, and if prompted to sign in, enter your work account.

The Office 365 Outlook connection has been created, and added to your app. Now, it's ready to be used.

Use the Office 365 Outlook connection in your app

Show email

  1. On the Insert menu, select Gallery, and then select a Text gallery control.

  2. Set its Items property to the following formula:

    Office365.GetEmails({fetchOnlyUnread:false})

    The gallery control is automatically populated with some of your emails.

  3. In the gallery, set the Text property of the first text box to ThisItem.From. Set the second text box to ThisItem.Subject. Set the third text box to ThisItem.Body. You can also resize the text boxes.

    The gallery control is automatically populated with the new properties.

  4. This function has several optional parameters available. Set the gallery's Items property to one of the following formulas:

    Office365.GetEmails({fetchOnlyUnread:false})
    Office365.GetEmails({fetchOnlyUnread:false, top:2})
    Office365.GetEmails({folderPath:"Sent Items", fetchOnlyUnread:false, top:2})
    Office365.GetEmails({folderPath:"Sent Items", fetchOnlyUnread:false, top:2, searchQuery:"powerapps"})
    Office365.GetEmails({folderPath:"Deleted Items", fetchOnlyUnread:false, top:2, skip:3})

Send email

  1. On the Insert menu, select Text, and then select Text input. Do this three times to create three different text input controls. Arrange them in a column:

  2. Rename them to:

    • inputTo
    • inputSubject
    • inputBody
  3. On the Insert menu, select Controls, and then select Button. Set its OnSelect property to the following formula:

    Office365.SendEmail(inputTo.Text, inputSubject.Text, inputBody.Text)

  4. Move the button so that it appears under all the other controls, and set its Text property to "Send email".

  5. Press F5, or select the Preview button ( ). Type in a valid email address in inputTo, and type whatever you want in the other two Text input controls.

  6. Select Send email to send the message. Press Esc to return to the default workspace.

Delete email

  1. On the Insert menu, select Gallery, and then select a Text gallery control.

  2. Set its Items property to the following formula:

    Office365.GetEmails({fetchOnlyUnread:false})

    The gallery control is automatically populated with some of your emails.

  3. In the gallery, set the Text property of the first text box to ThisItem.Id. Set the second text box to ThisItem.Subject. Set the third text box to ThisItem.Body.

  4. Select the first text box in the gallery, and rename it to EmailID:

    Close the Options pane

  5. Select the third text box in the gallery, and add a Button (Insert menu). Set the button's OnSelect property to the following formula:

    Office365.DeleteEmail(EmailID.Text)

  6. Press F5, or select the Preview button ( ). Select one of the emails in your gallery, and click the button.

    NOTE This deletes the selected email from your inbox. So, choose wisely.

  7. Press Esc to return to the default workspace.

Mark email as read

This section uses the same controls as Delete email.

  1. Set the button's OnSelect property to the following formula:

    Office365.MarkAsRead(EmailID.Text)

  2. Press F5, or select the Preview button ( ). Select one of the unread emails, and click the button.

  3. Press Esc to return to the default workspace.

View the available functions

This connection includes the following functions:

Function Name Description
GetEmails Retrieves emails from a folder
SendEmail Sends an email message
DeleteEmail Deletes an email message using the message id
MarkAsRead Marks an email message as having been read
ReplyTo Replies to an email message
GetAttachment Retrieves message attachment by id
OnNewEmail Triggers a flow when a new email arrives
SendMailWithOptions Send an email with multiple options and wait for the recipient to respond back with one of the options.
SendApprovalMail Send an approval email and wait for a response from the To recipient.

GetEmails

Get emails: Retrieves emails from a folder

Input properties

Name Data Type Required Description
folderPath string no Path of the folder to retrieve messages (default: 'Inbox')
top integer no Number of emails to retrieve (default: 10)
fetchOnlyUnread boolean no Retrieve only unread messages? (default: true)
includeAttachments boolean no If set to true, attachments will also be retrieved along with the email message. (default: false)
searchQuery string no Search query to filter emails
skip integer no Number of emails to skip (default: 0)
skipToken string no Skip token to fetch new page

Output properties

Property Name Data Type Required Description
value array yes Receive email messages that can include the following properties:
  • From (optional)
  • To (required)
  • Subject (required)
  • Body (required)
  • Importance (optional): "Low", "Normal", or "High"
  • HasAttachment (optional)
  • Id (optional)
  • IsRead (optional)
  • DateTimeReceived (optional)
  • Attachments (optional): Receive an attachment. Attachment properties include Id (required), ContentType (required), Name (required), ContentBytes (required).
  • Cc (optional)
  • Bcc (optional)
  • IsHtml (optional)

SendEmail

Send Email: Sends an email message

Input properties

Name Data Type Required Description
emailMessage yes Email message instance that can include the following properties:
  • Attachment (optional): Send an attachment. Attachment properties include Name (required), and ContentBytes (required).
  • From (optional)
  • Cc (optional)
  • Bcc (optional)
  • Subject (required)
  • Body (required)
  • Importance (optional): "Low", "Normal", or "High"
  • IsHtml (optional): Enter true or false
  • To (required): Separate email addresses with a comma.

Output properties

None.

DeleteEmail

Delete email: Deletes an email message by id

Input properties

Name Data Type Required Description
messageId string yes Id of the message to delete.

Output properties

None.

MarkAsRead

Mark as read: Marks an email message as having been read

Input properties

Name Data Type Required Description
messageId string yes Id of the message to be marked as read

Output properties

None.

ReplyTo

Reply to message: Replies to an email message

Input properties

Name Data Type Required Description
messageId string yes Id of the message to reply to
comment string yes Reply comment
replyAll boolean no Reply to all recipients

Output properties

None.

GetAttachment

Get attachment: Retrieves message attachment by id

Input properties

Name Data Type Required Description
messageId string yes Id of the message
attachmentId string yes Id of the attachment to download

Output properties

None.

OnNewEmail

On new email: Triggers a flow when a new email arrives

Input properties

Name Data Type Required Description
folderPath string no Email folder to retrieve (default: Inbox, Inbox\ToMe etc.)
to string no Recipient email addresses
from string no From address
importance string no Importance of the email (High, Normal, Low) (default: Normal)
fetchOnlyWithAttachment boolean no Retrieve only emails with an attachment
includeAttachments boolean no Include attachments
subjectFilter string no String to look for in the subject.

Output properties

Property Name Data Type Required Description
value array No

SendMailWithOptions

Send email with options: Send an email with multiple options and wait for the recipient to respond back with one of the options.

Input properties

Name Data Type Required Description
optionsEmailSubscription yes Subscription Request for Email options, including:
  • NotificationUrl (optional)
  • Message (optional)

Output properties

Property Name Data Type Required Description
id string No
resource string No
notificationType string No
notificationUrl string No

SendApprovalMail

Send approval email: Send an approval email and wait for a response from the To recipient.

Input properties

Name Data Type Required Description
approvalEmailSubscription yes Subscription Request for Approval Email, including:
  • NotificationUrl (optional)
  • Message (optional)

Output properties

Property Name Data Type Required Description
id string No
resource string No
notificationType string No
notificationUrl string No

Helpful links