没有办法获得发送方';使用Microsoft.Office.Interop、c#.net从outlook日历数据中删除电子邮件ID
我想获取发件人的电子邮件ID没有办法获得发送方';使用Microsoft.Office.Interop、c#.net从outlook日历数据中删除电子邮件ID,c#,.net,interop,outlook,C#,.net,Interop,Outlook,我想获取发件人的电子邮件ID 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, t
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
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
有人能解决这个问题吗?我想你可以从
mitem.Organizer
获取姓名,然后查看收件人
以找到匹配项
然后使用
PropertyAccessor
AppointmentItem通过mapi属性PR\u SMTP\u address
查找电子邮件地址。GetOrganizer()不一定是约会的发件人。在共享日历(首席/秘书)中,他们可能会有所不同
您可以使用从约会中获取发件人
AppointmentItem.SendUsingAccount
但根据我的经验(outlook 2010),除非您以发件人身份登录,否则该属性将返回null。但是检查组织者是否与发送者不同是很有用的