views:

210

answers:

1

I want to get the sender's emailId.

I am able to read all the data of calender by the below code but not the sender's emailId.

using Microsoft.Office.Interop.Outlook;

Microsoft.Office.Interop.Outlook.Application outlook = new Application();
Microsoft.Office.Interop.Outlook.NameSpace oNS = outlook.GetNamespace("MAPI");
oNS.Logon(Missing.Value, Missing.Value, true, true);
string currentUserEmail = oNS.CurrentUser.Address;
string currentUserName = oNS.CurrentUser.Name;
// Get the Calendar folder.
Microsoft.Office.Interop.Outlook.MAPIFolder objMAPIFolder =oNS.GetDefaultFolder(OlDefaultFolders.olFolderCalendar);
//Get the Sent folder
MAPIFolder sentFolder = oNS.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderSentMail);

Items sentMailItems = sentFolder.Items;

Items items = objMAPIFolder.Items;        

foreach (object item in sentMailItems)

{     
  if (item is MailItem)
  {

    MailItem oneMail = item as MailItem;        
    string mailContent = oneMail.HTMLBody;

    //item.sender is not available

  }    
 }

 foreach (object item in items)
 {  
  if (item is Microsoft.Office.Interop.Outlook.AppointmentItem)               
   {
    Microsoft.Office.Interop.Outlook.AppointmentItem mitem = item as     Microsoft.Office.Interop.Outlook.AppointmentItem;
    string subject = mitem.Subject;
    DateTime start = mitem.Start;
    DateTime end = mitem.End;
    string body = mitem.Body;
    string location = mitem.Location;
    string entryId = mitem.EntryID;   

    //sender email id not available   
    //string senderEmail = mitem.sender;
    }
 }
 oNS.Logoff();

But in any case whether reading appointments or sent folder emails, I am unable to obtain the sender's email Id.

does anybody have any solution for this problem ?

A: 

I think you can get the name from mitem.organizser and then look at the Recipients to find the match..

Then look up the email address via a mapi property PR_SMTP_ADDRESS using a PropertyAccessor.

76mel