首页 新闻 会员 周边 捐助

c#监视outlook的newmail事件,使用MSDN里的源码不成功,请帮忙看看,谢谢

0
悬赏园豆:5 [待解决问题]

http://msdn.microsoft.com/en-us/library/ms268754.aspx

如下:

使用如下代码会出现如下错误提示,请帮忙看看,谢谢

错误    1    “outlook.Form1”不包含“Application”的定义,并且找不到可接受类型为“outlookread.Form1”的第一个参数的扩展方法“Application”(是否缺少 using 指令或程序集引用?)    C:\test\outlookread\Form1.cs    32    22    outlook

 

 

      private void ThisAddIn_Startup(object sender, System.EventArgs e)
        {
            this.Application.NewMail += new Microsoft.Office.Interop.Outlook
                .ApplicationEvents_11_NewMailEventHandler(ThisApplication_NewMail);
        }

        private void ThisApplication_NewMail()
        {
            Outlook.MAPIFolder inBox = this.Application.ActiveExplorer()
                .Session.GetDefaultFolder(Outlook
                .OlDefaultFolders.olFolderInbox);
            Outlook.Items inBoxItems = inBox.Items;
            Outlook.MailItem newEmail = null;
            inBoxItems = inBoxItems.Restrict("[Unread] = true");
            try
            {
                foreach (object collectionItem in inBoxItems)
                {
                    newEmail = collectionItem as Outlook.MailItem;
                    if (newEmail != null)
                    {
                        if (newEmail.Attachments.Count > 0)
                        {
                            for (int i = 1; i <= newEmail
                               .Attachments.Count; i++)
                            {
                                newEmail.Attachments[i].SaveAsFile
                                    (@"C:\TestFileSave\" +
                                    newEmail.Attachments[i].FileName);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                string errorInfo = (string)ex.Message
                    .Substring(0, 11);
                if (errorInfo == "Cannot save")
                {
                    MessageBox.Show(@"Create Folder C:\TestFileSave");
                }
            }
        }
荷叶花开的主页 荷叶花开 | 初学一级 | 园豆:197
提问于:2014-05-06 22:36
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册