从 PowerApps 连接到 Office 365 OutlookConnect to Office 365 Outlook from PowerApps

Office 365 Outlook

如果连接到 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 to perform these functions in your app. 例如,可以添加“文本输入”控件来提示输入电子邮件的收件人、主题和正文,也可以添加“按钮”控件来发送电子邮件。For example, you can add Text input controls to ask for the recipient, the subject, and the body of the email, and add a Button control to send the email.

本主题演示了如何将 Office 365 Outlook 添加为连接、如何将 Office 365 Outlook 添加为应用的数据源,以及如何在不同的控件中使用此数据。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.

重要

截至本文撰写之时,日历操作不支持周期性活动。As of this writing, the calendar operation doesn't support recurring events.

先决条件Prerequisites

连接到 Office 365 OutlookConnect to Office 365 Outlook

  1. 添加数据连接并选择 Office 365 OutlookAdd a data connection and select Office 365 Outlook:

    连接到 Office 365

  2. 选择“连接”,如果系统提示你登录,请输入你的工作帐户。Select Connect, and if prompted to sign in, enter your work account.

Office 365 Outlook 连接已创建,并已添加到应用中。The Office 365 Outlook connection has been created and added to your app. 现在可供使用。Now, it's ready to be used.

显示邮件Show messages

  1. 在“插入”菜单上,选择“库”,然后选择“文本库”控件。On the Insert menu, select Gallery, and then select a Text gallery control.
  2. 将其 Items 属性设置为以下公式:Set its Items property to the following formula:

    Office365.GetEmails({fetchOnlyUnread:false})

    系统会自动使用一些电子邮件填充库控件。The gallery control is automatically populated with some of your emails.

  3. 在库中,将第一个标签的“Text”属性设置为“ThisItem.From”。In the gallery, set the Text property of the first label to ThisItem.From. 将第二个标签设置为“ThisItem.Subject”。Set the second label to ThisItem.Subject. 将第三个标签设置为“ThisItem.Body”。Set the third label to ThisItem.Body. 还可以重设标签大小。You can also resize the labels.

    系统会自动使用新属性填充库控件。The gallery control is automatically populated with the new properties.

  4. 此函数有几个可选参数。This function has several optional parameters available. 将库的“Items”属性设置为以下公式之一: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 a message

  1. 在“插入”菜单上,选择“文本”,然后选择“文本输入”。On the Insert menu, select Text, and then select Text input.
  2. 重复执行上述步骤两次,以创建三个框,再将这些框排入一列:Repeat the previous step two more times so that you have three boxes, and then arrange them in a column:

    一列中有三个框

  3. 将这些控件重命名为:Rename the controls to:

    • inputToinputTo
    • inputSubjectinputSubject
    • inputBodyinputBody
  4. 在“插入”菜单上,选择“控件”,然后选择“按钮”。On the Insert menu, select Controls, and then select Button. 将其 OnSelect 属性设置为以下公式:Set its OnSelect property to the following formula:

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

  5. 移动按钮,使其出现在所有其他控件下方,并将其 Text 属性设置为“发送电子邮件”。Move the button so that it appears under all the other controls, and set its Text property to "Send email".
  6. 按 F5 或选择预览按钮 (预览按钮)。Press F5, or select the Preview button (Preview button). 在“inputTo”中键入有效的电子邮件地址,并在其他两个“文本输入”控件中键入所需的任何内容。Type in a valid email address in inputTo, and type whatever you want in the other two Text input controls.
  7. 选择“发送电子邮件”来发送邮件。Select Send email to send the message. 按 Esc 返回默认工作区。Press Esc to return to the default workspace.

发送包含附件的邮件Send a message with an attachment

例如,可以创建应用,以便用户能够使用设备摄像头拍摄照片,并将照片作为附件发送。You can, for example, create an app in which the user takes pictures by using the device's camera and then sends them as attachments. 用户还可以将其他许多类型的文件附加到电子邮件应用。Users can also attach many other kinds of files to an email app.

若要向邮件添加附件,请按照上一部分中的步骤操作,不同之处在于(设置按钮的“OnSelect”属性时)添加用于指定附件的参数。To add an attachment to a message, follow the steps in the previous section, but add a parameter to specify an attachment (when you set the OnSelect property of the button). 此参数采用表结构,最多可以在其中为每个附件指定三个属性:This parameter is structured as a table in which you specify up to three properties for each attachment:

  • 名称Name
  • ContentBytesContentBytes
  • @odata.type

备注

只能为一个附件指定 @odata.type 属性,并能将它设置为空字符串。You can specify the @odata.type property for only one attachment, and you can set it to an empty string.

在以下示例中,照片将以 file1.jpg 的形式发送:In this example, a photo will be sent as file1.jpg:

Office365.SendEmail(inputTo.Text, inputSubject.Text, inputBody.Text, {Attachments:Table({Name:"file1.jpg", ContentBytes:Camera1.Photo, '@odata.type':""})})

在以下示例中,除了照片之外,还将发送音频文件:In this example, an audio file will be sent in addition to the photo:

Office365.SendEmail(inputTo.Text, inputSubject.Text, inputBody.Text, {Attachments:Table({Name:"file1.jpg", ContentBytes:Camera1.Photo, '@odata.type':""}, {Name:"AudioFile", ContentBytes:microphone1.audio })})

删除邮件Delete a message

  1. 在“插入”菜单上,选择“库”,然后选择“文本库”控件。On the Insert menu, select Gallery, and then select a Text gallery control.
  2. 将其 Items 属性设置为以下公式:Set its Items property to the following formula:

    Office365.GetEmails({fetchOnlyUnread:false})

    系统会自动使用一些电子邮件填充库控件。The gallery control is automatically populated with some of your emails.

  3. 在库中,将第一个标签的“Text”属性设置为“ThisItem.Id”。In the gallery, set the Text property of the first label to ThisItem.Id. 将第二个标签设置为“ThisItem.Subject”。Set the second label to ThisItem.Subject. 将第三个标签设置为“ThisItem.Body”。Set the third label to ThisItem.Body.
  4. 选择库中的第一个标签,然后将其重命名为“EmailID”:Select the first label in the gallery, and rename it to EmailID:

    重命名第一个标签

  5. 选择库中的第三个标签,然后添加一个“按钮”控件(使用“插入”菜单)。Select the third label in the gallery, and add a Button (Insert menu). 将按钮的“OnSelect”属性设置为以下公式:Set the button's OnSelect property to the following formula:

    Office365.DeleteEmail(EmailID.Text)

  6. 按 F5 或选择预览按钮 (Press F5, or select the Preview button (预览按钮)。). 选择库中的一封电子邮件,然后单击此按钮。Select one of the emails in your gallery, and click the button.

    备注

    这会从收件箱中删除选定电子邮件。This deletes the selected email from your inbox. 因此,请慎重选择。So, choose wisely.

  7. 按 Esc 返回默认工作区。Press Esc to return to the default workspace.

将邮件标记为已读Mark a message as read

此部分使用的控件与删除邮件部分一样。This section uses the same controls as Delete a message.

  1. 将按钮的“OnSelect”属性设置为以下公式:Set the button's OnSelect property to the following formula:

    Office365.MarkAsRead(EmailID.Text)

  2. 按 F5 或选择预览按钮 (Press F5, or select the Preview button (预览按钮)。). 选择一封未读电子邮件,再单击此按钮。Select one of the unread emails, and then click the button.
  3. 按 Esc 返回默认工作区。Press Esc to return to the default workspace.