將 Bot 連結到 Office 365 電子郵件Connect a bot to Office 365 email

適用于: SDK v4APPLIES TO: SDK v4

除了其他通道之外,Bot 還可透過 Office 365 電子郵件與使用者通訊。Bots can communicate with users via Office 365 email in addition to other channels. 當 Bot 設定為存取電子郵件帳戶時,它會在新的電子郵件送達時收到訊息。When a bot is configured to access an email account, it receives a message when a new email arrives. 然後,Bot 可以按照其商務邏輯進行回應。The bot can then respond as indicated by its business logic. 例如,Bot 可以傳送電子郵件回覆,確認收到的電子郵件中有訊息「嗨!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."

警告

建立 "spambot" 違反 Bot Framework 管理辦法,包括傳送不需要或未經請求的大量電子郵件的 Bot。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 認證,將 Bot 連結到電子郵件通道。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.

注意

您自己的個人電子郵件帳戶不應該用於 Bot,因為傳送至電子郵件帳戶的每個訊息都將轉送給 Bot。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. 這可能導致 Bot 不當地向寄件者傳送回應。This can result in the bot inappropriately sending a response to a sender. 因此,Bot 應該只使用專用的 O365 電子郵件帳戶。For this reason, bots should only use dedicated O365 email accounts.

若要新增電子郵件通道,請在 Azure 入口網站中開啟 Bot,按一下 [通道] 刀鋒視窗,然後按一下 [電子郵件] 。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 來自 bot 給使用者之傳入自訂電子郵件訊息的範例。The snippet below shows an example of the channelData for an incoming custom email message, from the bot to the user.

屬性Property 描述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

如果 Bot 未在 15 秒內傳回 200 OK HTTP 狀態碼以回應傳入的電子郵件訊息,電子郵件通道將會嘗試重新傳送訊息,因此 Bot 可能會收到相同的電子郵件訊息活動好幾次。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. 如需詳細資訊,請參閱 Bot 的運作方式 中的 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