Partager via


Connect a bot to Office 365 email

APPLIES TO: SDK v3

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."

Warning

It is a violation of the Bot Framework Code of Conduct to create "spambots", including bots that send unwanted or unsolicited bulk email.

Note

If you are using Microsoft Exchange Server, make sure you have enabled Autodiscover first before configuring email channel.

Configure email credentials

You can connect a bot to the Email channel by entering Office 365 credentials in the Email channel configuration. Federated authentication using any vendor that replaces AAD is not supported.

Note

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. For this reason, bots should only use dedicated O365 email accounts.

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.

Enter email credentials

The Email channel currently works with Office 365 only. Other email services are not currently supported.

Customize emails

The Email channel supports sending custom properties to create more advanced, customized emails using the channelData property.

Property Description
htmlBody The HTML to use for the body of the message.
subject The subject to use for the message.
importance The importance flag to use for the message: low, normal, or high.
toRecipients A semicolon (;) delimited string of email addresses to add to the message's To field.
ccRecipients A semicolon (;) delimited string of email addresses to add to the message's Cc (carbon copy) field.
bccRecipients A semicolon (;) delimited string of email addresses to add to the message's Bcc (blind carbon copy) field.

The following example message shows a JSON file that includes these channelData properties.

{
    "type": "message",
    "locale": "en-Us",
    "channelID": "email",
    "from": { "id": "mybot@mydomain.com", "name": "My bot"},
    "recipient": { "id": "joe@otherdomain.com", "name": "Joe Doe"},
    "conversation": { "id": "123123123123", "topic": "awesome chat" },
    "channelData":
    {
        "htmlBody": "<html><body style = /"font-family: Calibri; font-size: 11pt;/" >This is more than awesome.</body></html>",
        "subject": "Super awesome message subject",
        "importance": "high",
        "ccRecipients": "Yasemin@adatum.com;Temel@adventure-works.com"
    }
}

For more information about using channelData, see the .NET documentation.

Other considerations

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. For more information, see the how to troubleshooting timeout errors article.

Note

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