This article will show you how you can read the email from
outlook and get the email subject line using c#. In this article I have shown
how to get outlook email and display the subject line into listbox using
c#.net.
Some of my previous articles are as follows: Read
Outlook Inbox Mail And Email Count Of Inbox Using C#.Net, How
To Read XML File In DataSet And Display in DataGridview Using C#.Net, WebBrowser
Control in C#, Windows Application, Change
Control Font Size At Runtime / Dynamically Using C#.Net and VB.Net In Windows
Application, Export
GridView Data To Excel Sheet Using C#.Net In Windows Application, Blinking
Text in C#.Net Windows Application, Focus
on TextBox in C#.Net in Windows Application, Limit
OR Restrict Number of Characters in Textbox C#.Net In windows Application.
So for this article first we will care a new application and add the below code into the page. For this first we will add the button and list box control.
So for this article first we will care a new application and add the below code into the page. For this first we will add the button and list box control.
CODE
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using Outlook = Microsoft.Office.Interop.Outlook;
using System.Data;
namespace WindowsFormsApplication5
{
public partial class Form1 : Form
{
public
Form1()
{
InitializeComponent();
}
private
void button1_Click(object
sender, EventArgs e)
{
List<string> objSubjectList = new List<string>();
DataTable
objDt = new DataTable();
Outlook.Application
objApplication = new Outlook.Application();
Outlook.MAPIFolder
objInboxEmail =
objApplication.ActiveExplorer().Session.GetDefaultFolder(
Outlook.OlDefaultFolders.olFolderInbox);
for
(int i = 1; i <= objInboxEmail.Items.Count;
i++)
{
objSubjectList.Add(((Outlook.MailItem)objInboxEmail.Items[i]).Subject);
}
listBox1.DataSource =
objSubjectList;
}
}
}
|
In above code I have read the outlook email and created the subject line collection to bind it to the listbox control.
Now we have done run the application to check the output.
0 comments:
Please let me know your view