J
James
Hi there, I'm using c# to retrieve mail messages from outlook. However, i
have a problem of getting the sender's e-mail address. At present i can get
the sender's name but not e-mail address.
below is the code i'm using. can somebody please explain how to get the
sender's address?
Thanks
James
private void button1_Click(object sender, System.EventArgs e)
{
Outlook.Application oApp = new Outlook.Application();
// Get NameSpace and Logon.
Outlook.NameSpace oNS = oApp.GetNamespace("mapi");
oNS.Logon("Outlook", Missing.Value, false, true);
// Get the first contact from the Contacts folder.
Outlook.MAPIFolder cContacts =
oNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);
Outlook.Items oItems = cContacts.Items;
Outlook.MailItem oCt;
try
{
for(int i = 1; i <= oItems.Count; i++)
{
oCt = (Outlook.MailItem)oItems.Item(i);
//oCt = (Outlook.MailItem)oItems.GetFirst();
// Display some common properties.
ListViewItem tmp = new ListViewItem(oCt.SenderName);
tmp.SubItems.Add(oCt.Subject);
this.listView1.Items.Add(tmp);
}
}
catch(Exception ex)
{
Console.WriteLine(ex.Message);
}
finally
{
//Display
//oCt.Display(True)
//Log off.
oNS.Logoff();
//Clean up.
oApp = null;
oNS = null;
oItems = null;
oCt = null;
}
}
have a problem of getting the sender's e-mail address. At present i can get
the sender's name but not e-mail address.
below is the code i'm using. can somebody please explain how to get the
sender's address?
Thanks
James
private void button1_Click(object sender, System.EventArgs e)
{
Outlook.Application oApp = new Outlook.Application();
// Get NameSpace and Logon.
Outlook.NameSpace oNS = oApp.GetNamespace("mapi");
oNS.Logon("Outlook", Missing.Value, false, true);
// Get the first contact from the Contacts folder.
Outlook.MAPIFolder cContacts =
oNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);
Outlook.Items oItems = cContacts.Items;
Outlook.MailItem oCt;
try
{
for(int i = 1; i <= oItems.Count; i++)
{
oCt = (Outlook.MailItem)oItems.Item(i);
//oCt = (Outlook.MailItem)oItems.GetFirst();
// Display some common properties.
ListViewItem tmp = new ListViewItem(oCt.SenderName);
tmp.SubItems.Add(oCt.Subject);
this.listView1.Items.Add(tmp);
}
}
catch(Exception ex)
{
Console.WriteLine(ex.Message);
}
finally
{
//Display
//oCt.Display(True)
//Log off.
oNS.Logoff();
//Clean up.
oApp = null;
oNS = null;
oItems = null;
oCt = null;
}
}