我正在使用c#开发插件。每当我收到收件箱中的任何项目时,我都能收到通知。
this.Application.NewMailEx += new Outlook.ApplicationEvents_11_NewMailExEventHandler(olApp_NewMail);
private void olApp_NewMail(String itemCollection)
{
string [] strNewItems;
strNewItems = itemCollection.Split(',');
foreach (string newItem in strNewItems)
{
Outlook.MailItem mail = (Outlook.MailItem)Application.Session.GetItemFromID(newItem, Type.Missing);
string old_subj = mail.Subject;
string old_body = mail.Body;
MessageBox.Show(old_subj);
}
}
但问题在于事件处理程序我无法区分它是邮件项目还是会议项目。我该怎么办?
提前感谢。
此致 Jeeva
答案 0 :(得分:1)
你能不能这样做:
object item = Application.Session.GetItemFromID(newItem, Type.Missing);
Outlook.MailItem mailItem = item as Outlook.MailItem;
if (mailItem != null)
{
...
}
else
{
Outlook.MeetingItem meetingItem = item as Outlook.MeetingItem;
if (meetingItem != null)
{
...
}
}