Тёмный
No video :(

Office 365 IMAP OAuth With C# 

Blue Hippo
Подписаться 728
Просмотров 21 тыс.
50% 1

Now that basic authentication has been removed from exchange online, a lot of apps have broken and need to be switched over to using OAuth 2.0, this video covers an easy and simple way of doing so in C#
View the source code here: github.com/Blu...
Codewrecks video: • How to connect to Off...
Read more about the deprecation: learn.microsof...

Опубликовано:

 

1 окт 2022

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 69   
@elqueso5524
@elqueso5524 Год назад
Dude, I've been looking at authenticating using OAuth for days and my head spinning. I didn't see anything that explained, so simply, that it was just a freaking POST to get the token. I had everything else worked out with Azure, just couldn't figure out how to get the token. Thanks!
@bluehippotech
@bluehippotech Год назад
Haha exactly why I wanted to share it. I'm glad it helped :D
@hattinnh
@hattinnh Год назад
Thank you so much for taking the time to share this, much appreciated! All the best!
@horseradish4046
@horseradish4046 Год назад
followed exact instructions and app config, get Authentication Failed every time I try to authenticate the IMAP client
@harran9962
@harran9962 3 месяца назад
I have not tried yet but this is brilliant, thanks for the good video editing and information. I will try it to see how it works on my side.
@bluehippotech
@bluehippotech 3 месяца назад
Thanks for watching!
@viko3213
@viko3213 10 месяцев назад
Working like a charm, perfect, thank you.
@romainmornfall8116
@romainmornfall8116 Год назад
Thank you so much, been benging my head on that for so long
@semihcelikol7193
@semihcelikol7193 3 месяца назад
Thank you, that's good for me.
@dineshjakka5663
@dineshjakka5663 Год назад
Thank you so much for sharing your knowledge
@atahanates3341
@atahanates3341 Год назад
Hello, APIs used by my organization are not visible. Grant admin consent for blue tenant to same. What should i do ?
@chewabledrapery
@chewabledrapery Год назад
Very helpful thank you so much!
@cmbowers6
@cmbowers6 3 месяца назад
This is what I need but stuck on New-ServicePrincipal - is not recognized as the name of a cmdlet...
@bluehippotech
@bluehippotech 3 месяца назад
You need to login using the connect-exchangeonline cmdler first, hope that helps
@acislaghi
@acislaghi 3 месяца назад
What if I use Exchange Online without an Azure AD? I have a local AD...
@bluehippotech
@bluehippotech 3 месяца назад
That won't make a difference as long as you use exchange online for your mails
@FernandoCardenas-fo8bb
@FernandoCardenas-fo8bb Год назад
Someone managed to solve this error? Failed Authentication
@SachinSharma04
@SachinSharma04 Год назад
Please le me know how to access daily inbox email(day wise filter or timeinterval )
@SwapnamolAbraham
@SwapnamolAbraham Год назад
Thank you for this wonderful video. May I know how can we covert the email to html or text using mimekit?
@DanijelJames
@DanijelJames Год назад
This is incredible! ❤
@bluehippotech
@bluehippotech Год назад
Thank you, I hope it helped!
@Zisane21
@Zisane21 Месяц назад
What about sending emails? Isn't IMAP only for incoming?
@bluehippotech
@bluehippotech Месяц назад
Yeah it is, normal SMTP still works, this approach is only for IMAP.
@Zisane21
@Zisane21 Месяц назад
@@bluehippotech didn t MS remove basic auth for SMTP? Question is: can we get the token the way you described and use it to send email? This is what the stackoverflow article with the link to this video says
@bluehippotech
@bluehippotech Месяц назад
You can absolutely send mails with graph and an access token, what article on stack overflow are you referring to though? learn.microsoft.com/en-us/graph/api/user-sendmail?view=graph-rest-1.0&tabs=http
@Iteon
@Iteon Год назад
Can you please discribe what is in secrets.cs?
@bluehippotech
@bluehippotech Год назад
There's three variables. The tenant id, client id and client secret. It was just to not give you guys all my tenant details :D
@hatohadhatohad
@hatohadhatohad Год назад
Hello Bleu Hippotech ; Thank you for this great video . I have tested your code but I can only retrieve the old emails and not the new ones. Could you help me? Best Regards
@matasbernotas3815
@matasbernotas3815 Год назад
This is wonderful video! You helped me ot get it working instantly! Now a quick question.. How do you send email once connected? Is there anything else I need to do on Azure?
@bluehippotech
@bluehippotech Год назад
IMAP is only used for reading emails, to send emails you'll need to use SMPT which still supports basic authentication. Hope this helps!
@matasbernotas3815
@matasbernotas3815 Год назад
@@bluehippotech Wow thanks for instant reply! But isn't the Basic authentication deprecated soon and we should use approach in this video or I should start looking at Graph? Its getting a little confusing!
@bluehippotech
@bluehippotech Год назад
Basic authentication in office 365 got deprecated here in October for all other methods than SMTP. So smtp as the only one can still be used with basic authentication. Generally you should use a graph application whenever possible in my opinion. It's typically safer and easier.
@matasbernotas3815
@matasbernotas3815 Год назад
@@bluehippotech Thank you for making it so clear! You got a new subscriber here. More content on c# is always appreciated!
@DrMDodd
@DrMDodd Год назад
This is all well and good, but how can you send an email from Office 365 IMAP OAuth With C#
@bluehippotech
@bluehippotech Год назад
IMAP is only for receiving mails, for sending emails you'd use SMTP which still supports basic authentication :)
@Sudharsan_31
@Sudharsan_31 Год назад
Doubt .. for postman demonstration purpose we need to install module in ps using many commands? or It also needed for our c# code.
@bluehippotech
@bluehippotech Год назад
Postman is just for testing api, it has nothing to do with the code :D
@Sudharsan_31
@Sudharsan_31 Год назад
@@bluehippotech brother thanks for reply but one doubt I am asking about commands to install azuread in our system using ps ..it has any purpose with code or you have done this for postman demonstrations. Why I am asking is .. In my code at line of client.authenticate Throwing error like ` Mailkit.Security.AuthenticationException : ' Authentication failed ' please me out to sort this problem . Thanks 😊
@bluehippotech
@bluehippotech Год назад
It's necessary for setting up the service principal which gives access through the code
@adumred
@adumred Год назад
will it work for personal account that doesn't have office 365 subscription?
@bluehippotech
@bluehippotech Год назад
No it needs to have a mailbox before you can read from it.
@RobertoAtEpoca
@RobertoAtEpoca Год назад
How would you send an email?
@bluehippotech
@bluehippotech Год назад
With SMTP, basic auth with smtp isn't deprecated :D
@RobertoAtEpoca
@RobertoAtEpoca Год назад
@@bluehippotech Oh, good to know!
@SalvatorePostiglione
@SalvatorePostiglione Год назад
Grazie mi hai salvato
@zainamin8209
@zainamin8209 Год назад
When I write Connect-ExchangeOnline after hit enter open Microsoft pop up after select user account show error "Selected user account does not exist in tenant 'Microsoft Services' and cannot access the application 'fb78d390-0c51-40cd-8e17-fdbfab77341b' in that tenant. The account needs to be added as an external user in the tenant first. Please use a different account". What's the solution?
@bluehippotech
@bluehippotech Год назад
Are you sure you're using the same account for creating the azure ad application in the dashboard and in powershell?
@zainamin8209
@zainamin8209 Год назад
@@bluehippotech Yes
@bluehippotech
@bluehippotech Год назад
Have you tried running the powershell part line by line to check which cmdlet is throwing the error?
@zainamin8209
@zainamin8209 Год назад
@@bluehippotech Yes
@bluehippotech
@bluehippotech Год назад
@@zainamin8209 you're not giving me a lot to work with. Which cmdlet is giving the error? The error message is quite clear, I'd suspect you're using a wrong application ID. Maybe you're using the tenant ID instead or maybe you're using the object ID. Try to retrace your steps from the beginning
@masterbonzala
@masterbonzala Год назад
using HttpClient 💀
@zelalemtekeletsadik6431
@zelalemtekeletsadik6431 Год назад
Do you know why i get the below error on await client.PostAsync(url, new FormUrlEncodedContent(data)); {StatusCode: 400, ReasonPhrase: 'Bad Request', Version: 1.1, Content: System.Net.Http.StreamContent, Headers: { Pragma: no-cache Strict-Transport-Security: max-age=31536000; includeSubDomains
@boniu89
@boniu89 Год назад
Hello, I have the same problem like 'hm to' Line: await client.AuthenticateAsync(oauth2); MailKit.Security.AuthenticationException HResult=0x80131500 Message=Authentication failed. Source=MailKit This exception was originally thrown at this call stack: [External Code] OAuthApplication.MailHandler.IMAPConnectAsync(MailKit.Net.Imap.ImapClient, OAuthApplication.AccessTokenModel, MailKit.FolderAccess) in MailHandler.cs [External Code] OAuthApplication.MailHandler.GetFirstUnreadMessageAsync(OAuthApplication.AccessTokenModel) in MailHandler.cs [External Code] $.$(string[]) in Program.cs API Permission: Microsoft Graph: IMAP.AccessAsUser.All, offline_access, openid, SMTP.Send, User.Read Office 365 Exchange Online: IMAP.AccessAsApp, Mail.Read, Mail.ReadWrite, Mail.Send. All of them have Granted for.... with green sign. (My admin did it, because I am only User Role) Admin also did operation in Powershell. Get-MailboxPermission -Identity xxxx | Format-List IsOwner : False AccessRights : {FullAccess, ReadPermission} Deny : False InheritanceType : All User : NT AUTHORITY\SELF UserSid : xxxx Identity : xxx IsInherited : False IsValid : True ObjectState : Unchanged Can anyone help me?
@LukaSajovic
@LukaSajovic Год назад
I have the same problem. Did you manage to solve it?
@hmto919
@hmto919 Год назад
Thank you dude, your quick tutorial help me to understand this, I tried your steps but error occur when calling IMAPConnectAsync(client, accessToken), MailKit.Security.AuthenticationException: 'Authentication failed.' "This exception was originally thrown at this call stack: [External Code] OAuthApplication.MailHandler.IMAPConnectAsync(MailKit.Net.Imap.ImapClient, OAuthApplication.AccessTokenModel, MailKit.FolderAccess) in MailHandler.cs [External Code] OAuthApplication.MailHandler.GetAllMessagesAsync(OAuthApplication.AccessTokenModel) in MailHandler.cs [External Code] Program.$(string[]) in Program.cs" do you have any suggestion why this happen to me? I need this solution because I need to change my legacy apps credential method to OAuth2.
@obvidian
@obvidian Год назад
I have the same problem, did you find any solution to this?
@bluehippotech
@bluehippotech Год назад
Authentication failed means either the tenant permissions in graph are setup incorrectly or the tenant ID, client id or client secret is wrong.
@andreitrock
@andreitrock Год назад
@@bluehippotech how do u check the tenant permissions? you mean the api permissions?
@andreitrock
@andreitrock Год назад
also assuming im getting a token i guess i can rule out the wrong credentials part right?
@bluehippotech
@bluehippotech Год назад
If you're getting a Microsoft graph authentication token then your credentials are right. Just make sure your app has the service credential with full access to the mailbox and everything should be good. There's a link in the description to a github where you can see code examples
Далее
An Illustrated Guide to OAuth and OpenID Connect
16:36
Просмотров 577 тыс.
Gli occhiali da sole non mi hanno coperto! 😎
00:13
would you eat this? #shorts
00:39
Просмотров 3,5 млн
The weirdest way to loop in C# is also the fastest
12:55
The New Way of Calling Your Code in .NET 8 Is INSANE
12:34
SMTP Modern oauth Authentication with POSTMAN
7:54
Просмотров 9 тыс.
Email sending with Microsoft Graph API
43:52
Просмотров 19 тыс.
Limit app permissions to a specific mailbox - E40
20:22