Reading Emails from User Mailbox with IMAP and Modern Auth in .NetCore.

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
we go about using IMAP using modern authentication and use that access token that we get from Azure 80 to authenticate and read emails from the user's mailbox all right so let's get started so first of all what you need to do is register an application on Azure ad so if you're only concerned about registering application and getting the access token we already have another video on it you can check the link in the description below um for now let's create a sample IMAP application okay uh using oauth so I'll keep this setting as default I'll click on register all right so this sample as uh sample app has been created um I now I need you to go ahead and download this code from this GitHub repository I'll paste this link in the description below so I'll click on download and yeah so I have this file download it I'll uh just click on extract all right so we have extracted this file I'll open this file in visual studio so to mind you this this code sample as in c-sharp language using.net foreign so this app is opening right now meanwhile I'll create the credentials which are needed so what I need to do is uh go to the certificates and secret section of the app and create a new client secret uh click on I'll give a sample value over here you can give any value just click on ADD uh so the secret value is here you need to keep a note of it uh since this is displayed only once um I'll take a note of it okay so I've taken a note of it and then you need to go to the API permission section now click on ADD permission select apis in my organization uh type in office select Office 365 exchange online application permission type in IMAP and there you go I'll select IMAP click on ADD permission and the permission has been added so once the permission has added click on Grand admin consent and we have the admin consent as well all right so now we are good to go uh go back to the app which is open in Visual Studio I'll open program.cs so there are few values that we need to replace in program.cs the first value being is client ID and client secret so let me find those variables uh yeah there you go so I need to copy the client ID from the app I'll go to overview section I'll copy the client ID and paste it over here now I need to copy the client secret that we did in the notepad I'll copy and paste the client secret as well um as a scope I need to keep it as it is it is outlook.office.com IMAP access as users and then I need to paste in my tenant ID so I'll paste in my tenant ID over here okay once I have that I can move forward apart from that I guess I'll need the direct URL so I'll paste this redirect URL you need to go back to the authentication section of the app click on ADD platform select web and paste in the thank you redirect URL all right now I think we are good to call this app um it looks like it needs some dependencies uh it it does need a lot of dependencies let me check let me check this uh dependency I'll click on right and manage to get package uh click on browse okay right hopefully this will solar okay the error has been gone and I think we are going to call all right let's do this and call the IMAP function a console would open up so I think this is going to use the delegated application permission and we are using the client credential uh permission in the app so I think there is another change that we need to do before uh we sign in here okay so here you need to go to API permission section click on ADD permission okay so it is going to sign in Via browser so you need to go to the Microsoft graph delegated permission and select IMAP as the permission here and select IMAP access as users click on ADD and I think yeah that is added so this is the permission that we need this is the other permission if you are using the client credential code flow okay all right for now we need uh we need this permission so now I go back to the console or click on key that is redirecting it will ask me for my login credentials I'll enter that um on microsoft.com all right this app would like to read and write access to your mail click on accept okay so we got authorization code we got the access token and there you go uh we are getting each and every mail from the mailbox so right now I have created a for Loop it is giving me top five meals because that is the code that I have written and um yeah it says I have 793 mails in my inbox all right okay then uh that's all for today I'll paste this the link to this code in the chat and uh if you have any other questions or would you like me to explain this code to you please feel free to let me know in the comments and I'll be happy to do that wow thank you
Info
Channel: Graph Explorer
Views: 6,109
Rating: undefined out of 5
Keywords:
Id: Vd1CeaccChU
Channel Id: undefined
Length: 9min 7sec (547 seconds)
Published: Mon Oct 31 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.