开发者

Cant differentiate between MailItem and MeetingItem in NewMailEx

开发者 https://www.devze.com 2023-01-30 22:28 出处:网络
I am developing an addin using c#. I am able to receiv开发者_如何学Pythone notifications whenever i get any item in my inbox.

I am developing an addin using c#. I am able to receiv开发者_如何学Pythone notifications whenever i get any item in my inbox.

    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);
            }

        }

but the problem is in the event handler i am not able to distinguish whether it is mail item or meeting item. How should i do it?

thanks in advance.

Regards, Jeeva


Can you not do something like:

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)
    {
        ...
    }   
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号