Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I want to get outlook senders name and senders email address from my c# windows application.
below is my code but it returns errors. please help me.


C#
Microsoft.Office.Interop.Outlook.Application oApp = new  Microsoft.Office.Interop.Outlook.Application();

Microsoft.Office.Interop.Outlook.MailItem oMsg = (Microsoft.Office.Interop.Outlook.MailItem)oApp.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem);

                MessageBox.Show(oMsg.SenderName.ToString()); // here is the error
                MessageBox.Show(oMsg.SenderEmailAddress.ToString()); // here is the error



Thanks.
Posted
Updated 11-Apr-13 5:26am
v2
Comments
Bernhard Hiller 11-Apr-13 9:04am    
You create a new message object - consequently, the properties SenderName and SenderEmailAddress are not yet set.
If you want to get the sender of an existing email, you must create a MailItem obejct with that email.
Or is it something else you want to get?

1 solution

First of all, read Bernard Hiller comment.

See this:
Outlook 2013: http://msdn.microsoft.com/en-us/library/office/ff861332.aspx[^]
Outlook 2003: http://msdn.microsoft.com/en-us/library/office/aa210946%28v=office.11%29.aspx[^]

VBA:
VB
Set myOlApp = CreateObject("Outlook.Application")
Set myNamespace = myOlApp.GetNamespace("MAPI")
Set myFolder = myNamespace.GetDefaultFolder(olFolderInbox)
myFolder.Display
Set myItem = myFolder.Items(2)
myItem.Display
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900