Skip to main content

How to Read Mails from Outlook and Checking for particular User Mail

Microsoft.Office.Interop.Outlook .Application oApp;
Microsoft.Office.Interop.Outlook._NameSpace oNS;
Microsoft.Office.Interop.Outlook.MAPIFolder oFolder;
Microsoft.Office.Interop.Outlook._Explorer oExp;

oApp=new Microsoft.Office.Interop.Outlook.Application();
oNS = (Microsoft.Office.Interop.Outlook._NameSpace)oApp.GetNamespace("MAPI");
oFolder=oNS.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.
olFolderInbox);

oExp = oFolder.GetExplorer(false);
oNS.Logon(Missing.Value, Missing.Value, false, true);
Microsoft.Office.Interop.Outlook.Items items = oFolder.Items;

//checking for unread mails

foreach (Microsoft.Office.Interop.Outlook .MailItem mail in items)
{

if (mail.UnRead == true)
{

//Paste the code for already opened mails

if (mail.SenderName.Trim() == "crozzX")
{
//Paste the code for a particular User

}
}
else
{
//Paste the code for already opened mails
}
}

Comments

Popular posts from this blog

Difference between two Dates in C#.NET ?

To find the difference between two dates is very simple in VB — By using DateDiff method. But in C#, there is no direct method to do so. but there is a way to achive this. For this we need to understand TimeSpan Class. The following code snippet will show you how to find the difference. DateTime startTime = DateTime.Now; DateTime endTime = DateTime.Now.AddSeconds( 75 ); TimeSpan span = endTime.Subtract ( startTime ); Console.WriteLine( “Time Difference (seconds): ” + span.Seconds ); Console.WriteLine( “Time Difference (minutes): ” + span.Minutes ); Console.WriteLine( “Time Difference (hours): ” + span.Hours ); Console.WriteLine( “Time Difference (days): ” + span.Days ); By concatenating all this you will get the difference between two dates. You can also use span.Duration(). There are certain limitations to. The TimeSpan is capable of returning difference interms of Days, Hours, mins and seconds only. It is not having a property to show difference interms of Months and years. Hope this...

.NET Reflection

Reflection is the feature in .Net, which enables us to get some information about object in runtime. That information contains data of the class. Also it can get the names of the methods that are inside the class and constructors of that object. To write a C# .Net program which uses reflection, the program should use the namespace System.Reflection. To get type of the object, the typeof operator can be used. There is one more method GetType(). This also can be used for retrieving the type information of a class. The Operator typeof allow us to get class name of our object and GetType() method uses to get data about object?s type. Example program: namespace Reflection { public class TestDataType { public TestDataType() { counter = 1; } public TestDataType(int c) { counter = c; } private int counter; public int Inc() { return counter++; } public int Dec() ...

Splash Screen in Visual Studio 2008 using C#.NET

Creating Splash Screen is now very easy just follow these steps to make your application look very rich. 1.Suppose, Welcome.cs is your main form and SplashScreen.cs is your splash screen form. 2.Write the following code in the page_load event of your Welcome.cs form Hide(); bool done = false; ThreadPool.QueueUserWorkItem((x) => { using (var splashForm = new SplashForm()) { splashForm.Show(); while (!done) Application.DoEvents(); splashForm.Close(); } }); Thread.Sleep(3000); // Emulate hardwork done = true; Show(); 3. It's done!!