是否无法使用Microsoft.Office.Interop,c#.net从Outlook日历数据中获取发件人的电子邮件ID

时间:2009-07-31 11:01:56

标签: c# .net interop outlook

我想收到发件人的emailId。

我可以通过以下代码读取日历的所有数据,但不能读取发件人的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();

但无论如何阅读约会或发送文件夹电子邮件,我都无法获得发件人的电子邮件ID。

有没有人解决这个问题?

2 个答案:

答案 0 :(得分:1)

我认为您可以从mitem.organizser获取名称,然后查看Recipients以找到匹配项。

然后使用PR_SMTP_ADDRESS通过mapi属性PropertyAccessor查找电子邮件地址。

答案 1 :(得分:0)

AppoitnmentItem.GetOrganizer()不一定是约会的发送者。在共享日历(主要/秘书)中,它们可能不同。

您可以使用约会来获取发件人 的 AppointmentItem.SendUsingAccount

但根据我的经验(outlook 2010),除非您以发件人身份登录,否则该属性将返回null。但是检查组织者是否与发件人不同是很有用的。