使用C#的Outlook加载项 [英] Outlook Add In using C#

查看:305
本文介绍了使用C#的Outlook加载项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须创建一个加载项,在其中必须读取Outlook的特定文件夹(例如Inbox-> TestFolder)中的邮件,然后将该邮件传输到Web服务器.我已经创建了将邮件移动到TestFolder的规则.
我能够触发NewMailEx事件,但是由于在规则处理之前就触发了NewMailEx,因此我无法读取测试文件夹中的邮件
如果可能的话,请通过一些代码帮助我

还是我可以将Window Service用作同一个窗口,更好的选择是Window Service或Outlook Addin


I have to create a Add In in which i have to read mails inside a particular folder of Outlook (like Inbox->TestFolder)and then transfer that mail to webserver. i have created a rule to move mails to TestFolder.
I am able to fire NewMailEx event but i am not able to read mails inside test folder since NewMailEx fires before rules process
Please help me on this if possible with some code

or can i use window service for the same ,what will be the better option Window service or outlook Addin


private void ThisAddIn_Startup(object sender, System.EventArgs e)
        {
            _Explorers = this.Application.Explorers;

            _Explorers.Application.NewMailEx += new Outlook.ApplicationEvents_11_NewMailExEventHandler(Application_NewMailEx);


        }







private void Application_NewMailEx(string EntryID)
        {
           
            Microsoft.Office.Interop.Outlook.MAPIFolder inboxFolder = null;
            Microsoft.Office.Interop.Outlook.MAPIFolder subFolder = null;
           
            outlookNamespace = this.Application.GetNamespace("MAPI");
            outlookNamespace.Logon(null, null, false, false);

            inboxFolder = outlookNamespace.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox);
            subFolder = inboxFolder.Folders["HR"];


            foreach (Microsoft.Office.Interop.Outlook.MailItem mail in subFolder.Items)
            {
                if (mail.UnRead == true)
                {
                    foreach (Microsoft.Office.Interop.Outlook.Attachment attachment in mail.Attachments)
                    {
                        filename = folderpath + attachment.FileName;
                        attachment.SaveAsFile(filename);
                    }
                }
            }

            
        }

推荐答案

您为什么不将邮件移动到文件夹操作作为事件的一部分而不是规则来进行?在这种情况下,可以确定所需的所有消息都在目标文件夹中...
Why don''t you perform the mail-move-to-folder action as part of your event, instead of a rule? In this case, you can be certain that all messages you want are in the target folder...


这篇关于使用C#的Outlook加载项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆