当新邮件到达Outlook收件箱时,将电子邮件副本保存在指定的路径中 [英] Save a copy of email in specified path when new mail arrive in Inbox of Outlook

查看:96
本文介绍了当新邮件到达Outlook收件箱时,将电子邮件副本保存在指定的路径中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我想在新邮件到达收件箱后立即将电子邮件副本保存在C:\ Temp文件夹中.

为此,我在Visual Studio中使用了Outlook插件,

创建了NewMailEx方法.
我可以在收到新邮件时收到消息框


问题:我无法将邮件复制到指定路径

下面的代码将给出更多的想法.

Hi,

I want to save a copy of email in C:\Temp folder as soon as a new mail arrive in inbox.

For this i used outlook addin in Visual studio,

Created NewMailEx method.
I am able to get message box when new mail arrive


PROBLEM: I am not able to copy mail to specified path

Below code will give more idea.

public partial class ThisAddIn
    {
        private Outlook.Explorers _Explorers;  // the Outlook Explorers collection
        private Outlook.Inspectors _Inspectors;  // the Outlook Inspectors collection
        private Outlook.NameSpace outlookNamespace;
        private Outlook.Application outlookObj;
        private void ThisAddIn_Startup(object sender, System.EventArgs e)
        {
            _Explorers = this.Application.Explorers;
            _Inspectors = this.Application.Inspectors;

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

            //  this.Application.ItemLoad +=
            //new Outlook.ApplicationEvents_11_ItemLoadEventHandler(GetMailItemLocation);

            outlookNamespace = this.Application.GetNamespace("MAPI");
        }
        private void Application_NewMailEx(string EntryID)
        {
            Outlook.MailItem newMail = (Outlook.MailItem)_Explorers.Application.Session.GetItemFromID(
                EntryID, System.Reflection.Missing.Value);

            string Path = @"C:\Temp\" + newMail.Subject + ".msg";
            //Alternate way
            string uPath = @"C:\Temp\";

            newMail.SaveAs(Path, Outlook.OlSaveAsType.olMSG);
            newMail.SaveAs(uPath, Outlook.OlSaveAsType.olMSG);

            if (newMail.Subject != null)
            {
                MessageBox.Show("From: " + newMail.SenderEmailAddress + "\nSubject: " +
                    newMail.Subject, "New Email", MessageBoxButtons.OK);
            }
            else
            {
                MessageBox.Show("You''ve got mail.");
            }
        }
        private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
        {
            _Explorers = null;
            _Inspectors = null;
            GC.Collect();
            GC.WaitForPendingFinalizers();
        }

        private void InternalStartup()
        {
            this.Startup += new System.EventHandler(ThisAddIn_Startup);
            this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
        }
        
        #endregion
    }

推荐答案

相同的代码有效..
无需更改
Same code worked..
Nothing need to be changes


这篇关于当新邮件到达Outlook收件箱时,将电子邮件副本保存在指定的路径中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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