i just wanna read outlook inbox email using c#
Loading
i just wanna read outlook inbox email using c#
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Naimish MakwanaRank #324 · 7.7K reputationPosted Sep 4, 2024, 3:46 AM EDT
Sure, I can help with that! Here’s a basic example of how you can read emails from your Outlook inbox using C# and the Microsoft.Office.Interop.Outlook library:
Add Reference: First, add a reference to the
Microsoft.Office.Interop.Outlooklibrary in your project.Code Example:
using System; using Outlook = Microsoft.Office.Interop.Outlook; class Program { static void Main(string[] args) { ReadOutlookMail(); } static void ReadOutlookMail() { Outlook.Application outlookApp = new Outlook.Application(); Outlook.NameSpace outlookNamespace = outlookApp.GetNamespace("MAPI"); outlookNamespace.Logon("", "", Missing.Value, Missing.Value); Outlook.MAPIFolder inboxFolder = outlookNamespace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox); Outlook.Items mailItems = inboxFolder.Items; foreach (Outlook.MailItem item in mailItems) { Console.WriteLine("Subject: " + item.Subject); Console.WriteLine("From: " + item.SenderName); Console.WriteLine("Received: " + item.ReceivedTime.ToString()); Console.WriteLine("Body: " + item.Body); Console.WriteLine("Attachments: " + item.Attachments.Count); Console.WriteLine("-----------------------------------"); } } }This code will log into Outlook, access the inbox, and print out the subject, sender, received time, body, and attachment count of each email in the inbox12.
Thanks
Jaimin ShethiyaRank #177 · 13.7K reputationPosted Sep 4, 2024, 6:02 AM EDT
Hello Yougesh,
you can refer below link
https://developer.microsoft.com/en-us/graph/graph-explorer
You need to install miscrosfot graph nuget package as well.
Thanks