您现在访问的是微软AZURE全球版技术文档网站,若需要访问由世纪互联运营的MICROSOFT AZURE中国区技术文档网站,请访问 https://docs.azure.cn.

将机器人连接到 Office 365 电子邮件Connect a bot to Office 365 email

适用于: SDK v4APPLIES TO: SDK v4

除了其他通道,机器人还可以通过 Office 365 电子邮件与其他用户通信。Bots can communicate with users via Office 365 email in addition to other channels. 当机器人经过配置,可以访问电子邮件时,如果有新邮件到达,它会收到一条消息。When a bot is configured to access an email account, it receives a message when a new email arrives. 然后机器人可以按照其业务逻辑做出响应。The bot can then respond as indicated by its business logic. 例如,机器人可能发送确认电子邮件已收到的电子邮件回复,邮件内容为“你好!For example, the bot could send an email reply acknowledging an email was received with the message, "Hi! 感谢你下达的订单!Thanks for your order! 我们将立即开始处理。”We will begin processing it immediately."

警告

创建“spambots”(包括发送不需要或未经请求的批量电子邮件的机器人)将被视为违反 Bot Framework 行为准则It is a violation of the Bot Framework Code of Conduct to create "spambots", including bots that send unwanted or unsolicited bulk email.

备注

如果使用 Microsoft Exchange Server,请确保先启用自动发现,然后再配置电子邮件通道。If you are using Microsoft Exchange Server, make sure you have enabled Autodiscover first before configuring email channel.

配置电子邮件凭据Configure email credentials

可以通过在电子邮件通道配置中输入 Office 365 凭据,将机器人连接到电子邮件通道。You can connect a bot to the Email channel by entering Office 365 credentials in the Email channel configuration. 不支持使用任何替换 AAD 的供应商的联合身份验证。Federated authentication using any vendor that replaces AAD is not supported.

备注

不应该将自己的个人电子邮件帐户用于机器人,因为发送到该电子邮件帐户的每个邮件都将转发给机器人。You should not use your own personal email accounts for bots, as every message sent to that email account will be forwarded to the bot. 这可能导致机器人不恰当地向发件人发送响应。This can result in the bot inappropriately sending a response to a sender. 因此,机器人应仅使用专用的 O365 电子邮件帐户。For this reason, bots should only use dedicated O365 email accounts.

若要添加电子邮件通道,在 Azure 门户中打开机器人,单击“通道” 边栏选项卡,然后单击“电子邮件” 。To add the Email channel, open the bot in the Azure Portal, click the Channels blade, and then click Email. 输入有效的电子邮件凭据,然后单击“保存” 。Enter your valid email credentials and click Save.

输入电子邮件凭据

电子邮件通道当前仅使用 Office 365。The Email channel currently works with Office 365 only. 目前不支持其他电子邮件服务。Other email services are not currently supported.

自定义电子邮件Customize emails

电子邮件通道支持通过使用活动属性发送自定义值,以创建更高级的自定义电子邮件 channelDataThe Email channel supports sending custom values to create more advanced, customized emails by using the activity channelData property. 下面的代码片段显示 channelData 传入自定义电子邮件消息(从机器人到用户)的示例。The snippet below shows an example of the channelData for an incoming custom email message, from the bot to the user.

propertiesProperty 说明Description
htmlBodyhtmlBody 用于邮件正文的 HTML。The HTML to use for the body of the message.
subjectsubject 用于邮件的主题。The subject to use for the message.
importanceimportance 用于邮件的重要性标志:lownormalhighThe importance flag to use for the message: low, normal, or high.
toRecipientstoRecipients 添加到邮件“收件人”字段的用分号 (;) 分隔的电子邮件地址字符串。A semicolon (;) delimited string of email addresses to add to the message's To field.
ccRecipientsccRecipients 添加到邮件“Cc(抄送)”字段的用分号 (;) 分隔的电子邮件地址字符串。A semicolon (;) delimited string of email addresses to add to the message's Cc (carbon copy) field.
bccRecipientsbccRecipients 添加到邮件“Bcc(密件抄送)”字段的用分号 (;) 分隔的电子邮件地址字符串。A semicolon (;) delimited string of email addresses to add to the message's Bcc (blind carbon copy) field.

有关活动属性的详细信息 channelData ,请参阅 创建自定义电子邮件。For more information about the activity channelData property, see Create a custom Email message.

其他注意事项Other considerations

如果机器人没有在 15 秒内返回 HTTP 状态代码“200 正常”作为对传入电子邮件的响应,则电子邮件通道会尝试重新发送该邮件,因此机器人可能会多次收到同一电子邮件活动。If your bot does not return a 200 OK HTTP status code within 15 seconds in response to an incoming email message, the email channel will try to resend the message, and your bot may receive the same email message activity a few times. 有关详细信息,请参阅 机器人工作原理 一文和 如何排查超时错误一文中的 HTTP 详细信息部分。For more information, see the HTTP details section in How bots work and the how to troubleshooting timeout errors article.

备注

如果使用的是启用了 MFA 的 Office 365 帐户,请确保先为指定的帐户禁用 MFA,然后再为电子邮件通道配置帐户。If you are using an Office 365 account with MFA enabled on it, make sure you disable MFA for the specified account first, then you can configure the account for the email channel. 否则,连接将失败。Otherwise, the connection will fail.

其他资源Additional resources