diff --git a/FAQ.md b/FAQ.md index 47cbf804bb..905da86203 100644 --- a/FAQ.md +++ b/FAQ.md @@ -37,6 +37,7 @@ * [Why doesn't ImapFolder.MoveTo() move the message out of the source folder?](#imap-move-does-not-move) * [How can I mark messages as read using IMAP?](#imap-mark-as-read) * [How can I re-synchronize the cache for an IMAP folder?](#imap-folder-resync) +* [How can I login using a shared mailbox in Office365?](#office365-shared-mailboxes) ### SmtpClient @@ -1731,6 +1732,31 @@ static void ResyncFolder (ImapFolder folder, List cache, ref } ``` +### Q: How can I login using a shared mailbox in Office365? + +```csharp +var result = await GetPublicClientOAuth2CredentialsAsync ("IMAP", "sharedMailboxName@custom-domain.com"); + +// Note: We always use result.Account.Username instead of `Username` because the user may have selected an alternative account. +var oauth2 = new SaslMechanismOAuth2 (result.Account.Username, result.AccessToken); + +using (var client = new ImapClient ()) { + await client.ConnectAsync ("outlook.office365.com", 993, SecureSocketOptions.SslOnConnect); + await client.AuthenticateAsync (oauth2); + + // ... + + await client.DisconnectAsync (true); +} +``` + +Notes: + +1. The `GetPublicClientOAuth2CredentialsAsync()` method used in this example code snippet can be found in the +[ExchangeOAuth2.md](ExchangeOAuth2.md#desktop-and-mobile-applications) documentation. +2. Some users have reported that they need to use `"username@custom-domain.com\\sharedMailboxName"` as their +username instead of `"sharedMailboxName@custom-domain.com"`. + ## SmtpClient ### Q: Why doesn't the message show up in the "Sent Mail" folder after sending it?