Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shared Mailbox Office 365 #1770

Closed
p3root opened this issue Jul 11, 2024 · 7 comments
Closed

Shared Mailbox Office 365 #1770

p3root opened this issue Jul 11, 2024 · 7 comments
Labels
question A question about how to do something

Comments

@p3root
Copy link

p3root commented Jul 11, 2024

Hi @jstedfast !

I have some issues authenticating the SMTPClient to Office365 using a shared mailbox.
Connecting to my personal account works, but the shared mailbox is not possible.

I have attached some logs for you:

S: 220 AM0PR02CA0134.outlook.office365.com Microsoft ESMTP MAIL Service ready at Thu, 11 Jul 2024 11:46:42 +0000
C: EHLO .....
S: 250-AM0PR02CA0134.outlook.office365.com Hello [212.52.200.46]
S: 250-SIZE 157286400
S: 250-PIPELINING
S: 250-DSN
S: 250-ENHANCEDSTATUSCODES
S: 250-STARTTLS
S: 250-8BITMIME
S: 250-BINARYMIME
S: 250-CHUNKING
S: 250 SMTPUTF8
C: STARTTLS
S: 220 2.0.0 SMTP server ready
C: EHLO ....
S: 250-AM0PR02CA0134.outlook.office365.com Hello [212.52.200.46]
S: 250-SIZE 157286400
S: 250-PIPELINING
S: 250-DSN
S: 250-ENHANCEDSTATUSCODES
S: 250-AUTH LOGIN XOAUTH2
S: 250-8BITMIME
S: 250-BINARYMIME
S: 250-CHUNKING
S: 250 SMTPUTF8
C: AUTH XOAUTH2 dXNlcj1wYXRy...
S: 535 5.7.3 Authentication unsuccessful [AM0PR02CA0134.eurprd02.prod.outlook.com 2024-07-11T11:46:49.042Z 08DCA18218166FB4]

I always get the "S: 535 5.7.3 Authentication unsuccessful". I have enabled SMTP AUTH in my tenant and for my user.

Token seems to be valid, I can connect to my personal mailbox.

mailbox.Username = "office@.."; //personal user is patrik....

var token = await OAuthUtils.GetValidMailboxAccessToken(db, mailbox.Id);
var oauth = new SaslMechanismOAuth2(mailbox.Username, token); 
await client.AuthenticateAsync(oauth);

I also tried it with "patrik@...\office". Did not work either. Could you provide any help? Or do I need to ask MS.

THANKS
Patrik

@jstedfast
Copy link
Owner

You probably need to ask Microsoft Support because I don't know how to format the username string to do what you are trying to do.

@jstedfast jstedfast added the question A question about how to do something label Jul 11, 2024
@jstedfast
Copy link
Owner

If you find out, can you share the answer here? If you can do that, I'll update the FAQ to add this. I'm sure I've gotten other questions about this but I don't remember if/what the answer was.

FWIW, there were other questions about this in the past: https://github.com/jstedfast/MailKit/issues?q=is%3Aissue+is%3Aclosed+shared+mailbox

This is probably the most likely answer to your question: #1412 (comment)

@p3root
Copy link
Author

p3root commented Jul 11, 2024

https://learn.microsoft.com/en-us/exchange/client-developer/legacy-protocols/how-to-authenticate-an-imap-pop-smtp-application-by-using-oauth#sasl-xoauth2-authentication-for-shared-mailboxes-in-office-365

Check this link. But does not work either. I will contact MS and let you know.

@p3root
Copy link
Author

p3root commented Sep 4, 2024

@jstedfast
After several weeks of phone calls, emails, etc. with microsoft we got a solution.

For IMAP you need to use the shared mailboxes email address.
For SMTP use your users email address
Token is the same for both!

@p3root
Copy link
Author

p3root commented Sep 4, 2024

Make sure to have SMTP Authentication enabled. Can also be that the shared mailbox needs to have a license. but I could not verify this right now. Updates pending!

@jstedfast
Copy link
Owner

For IMAP you need to use the shared mailboxes email address.

So would you use "[email protected]", for example? Or would it be "[email protected]\\sharedMailbox"?

@p3root
Copy link
Author

p3root commented Sep 4, 2024

You need to use [email protected]

jstedfast added a commit that referenced this issue Sep 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question A question about how to do something
Projects
None yet
Development

No branches or pull requests

2 participants