在C#中从路径到新Outlook.MailItem的创建/打开现有消息 [英] Create/Open existing msg from path to new Outlook.MailItem in c#

查看:293
本文介绍了在C#中从路径到新Outlook.MailItem的创建/打开现有消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我想从磁盘上的现有文件夹创建一个Outlook.MailItem(我相信).我将路径存储在字符串中,并希望通过它来保存正文和附件.

Hello I'd like to create a Outlook.MailItem ( I believe ) from an existing one located on disk. I have the path stored in a string, and would like to access to save the body and attachments from it.

我似乎无法弄清楚如何在c#中打开它并访问它.

I can't seem to figure out how to open it in c# and access it.

目前我有一些类似的东西

currently I have something along the lines of

其中fl的计算结果类似于"C:\ users \ msgs \ email.msg"

where fl evaluates out to something like "C:\users\msgs\email.msg"

感谢您的时间

Outlook.Application app = new Outlook.Application();

        try
        {

            foreach (String fl in Directory.GetFiles(docInfo.LocalPath + _preprocessorDirectory))
            {
                if (Regex.IsMatch(fl.Trim(), _regex, RegexOptions.IgnoreCase))
                {

                   Outlook.MailItem email = new Outlook.MailItem(fl);
                   SaveAttachments(email);
                   SaveBody(email);
                }
            }
        }
        catch (Exception ex)
        {
            logger.Error("Error in Process for document " + docInfo.OriginalPath, ex);
            callback.Invoke(docInfo, false);
        }
        return false;

推荐答案

要在Outlook中打开项目,请尝试:

To open an item in outlook try:

var email = (Outlook.MailItem)app.Session.OpenSharedItem(fl)

从那里,您还可以访问Attachments属性和Body属性.

From there, you can access the Attachments property and Body property as well.

此外,正如我在评论中提到的,如果Regex.IsMatch要确定文件扩展名,请使用

Also, as I mentioned in my comment if the Regex.IsMatch is to determing the file extension, use Path.GetExtension() instead

这篇关于在C#中从路径到新Outlook.MailItem的创建/打开现有消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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