Exchange WebServices将消息另存为msg文件 [英] Exchange WebServices save message as msg file

查看:169
本文介绍了Exchange WebServices将消息另存为msg文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要求从我们的Exchange服务器上的某个文件夹中获取所有电子邮件,将所有附件和邮件本身保存到文件系统。

我可以保存附件,但我'我的消息本身有问题。



我们的交换服务器是2010 SP2,所以我使用EWS连接,获取消息并保存附件。这些文件将进入文档存储库系统。这个系统可以显示.msg文件,所以我需要把电子邮件保存为.msg。



从我到目前为止发现的,我只能保存邮件作为.eml文件。



我以为我可以通过将.eml转换为.msg来解决这个问题,但还没有找到办法解决这个问题。



然后我想我可以从EWS应用程序中获取某种ID之后使用Microsoft.Office.Interop.Outlook从控制台应用程序获取消息。我找不到两个相同的ID。



有人有什么建议吗?我必须为我们的文档存储库系统获取.msg的消息文件。



提前谢谢,



tshaffer

I have a requirement to get all email messages from a certain folder on our exchange server, save all attachments and the message itself to the file system.
I can save the attachments, but I'm having an issue with the message itself.

Our exchange server is 2010 SP2, so I am using EWS to connect, get the messages and save the attachments. These files are going into a document repository system. This system can display .msg files, so I need the emails to save as .msg.

From what I've found so far, I can only save the messages as .eml files.

I thought I could work with this by converting the .eml to .msg, but not finding a way to do this yet.

Then I thought I could get the messages from a console application using Microsoft.Office.Interop.Outlook after getting some kind of Id from the EWS application. I can't find id's in both that are the same.

Does anyone have any suggestions? I have to get the message files as .msg for our document repository system.

thank you in advance,

tshaffer

推荐答案

http:// www .independentsoft.de / exchangewebservices / tutorial / downloadmessagetomsgfile.html



Exchange Web Services .NET提供了将邮件和其他项目保存为Outlook .msg文件的功能。它适用于ANSI和Unicode .msg文件。
http://www.independentsoft.de/exchangewebservices/tutorial/downloadmessagetomsgfile.html

Exchange Web Services .NET offers feature to save messages and other items as Outlook .msg files. It works with ANSI and Unicode .msg files.


我决定不使用EWS,而是使用Microsoft.Office.Outlook.Interop。



我在开发PC上运行的代码如下:



I have decided not to use EWS, instead I am using Microsoft.Office.Outlook.Interop.

I have the following code working well on my development PC:

log = New cLog()
        Dim AppKeys As IDictionary = ConfigurationManager.GetSection("AppKeys")
        Dim app As New Microsoft.Office.Interop.Outlook.Application()
        Dim box As String
        log.Write("Starting to retrieve mail.")
        Try
            box = AppKeys("mailbox")
            tempLoc = Environment.CurrentDirectory & "\" & ConfigurationManager.AppSettings("TempLoc")
            Dim ns As Microsoft.Office.Interop.Outlook.NameSpace = app.Session
            log.Write("Namespace is: " & ns.CurrentProfileName)
            Dim recipient As Recipient = ns.CreateRecipient(box)
            log.Write("recipient is: " & recipient.Name)
            recipient.Resolve()
            log.Write("recipient resolved")
            Dim inbox As Folder = ns.GetSharedDefaultFolder(recipient, OlDefaultFolders.olFolderInbox)
            log.Write("Got inbox")
            Dim subject As String
            Dim mailCount As Int32 = 0
            log.Write("There are " + inbox.Items.Count.ToString() + " Emails in " + box)
            For Each mm As MailItem In inbox.Items
                If Not subject Is Nothing Then
                    For Each attach As Attachment In mm.Attachments
                        attach.SaveAsFile(tempLoc & filename & attach.FileName.Substring(attach.FileName.Length - 4, 4))
                    Next
                        ''Save email message as msg and create idx file for it
                        filename = filename.Substring(0, filename.Length - 2) & "_" & count + 1
                        mm.SaveAs(tempLoc & filename & ".msg", OlSaveAsType.olMSG)
                End If
            Next
        Catch ex As System.Exception
            log.Write("Excpetion getting mail: " & ex.Message)
        End Try
        app.Quit()





但是,当我将编译后的代码移动到生产PC(安装了Office 2010,与我的开发PC相同)时,我现在得到了此行上出现以下错误:ns.GetSharedDefaultFolder:



由于注册表操作失败或安装问题。重新启动Outlook,然后重试。如果问题仍然存在,请重新安装。



我在使用Microsoft.Office.Outlook.Interop将.MSG文件转换为的同一台生产PC上运行一个单独的应用程序。 PDF和没有问题的运行。



我能想到的唯一区别是我的开发PC是Windows XP而生产PC是Windows 7。



任何想法都将不胜感激!



谢谢!



However, when I move the compiled code to a production PC (with Office 2010 installed, same as my development PC) I now get the following error on this line, "ns.GetSharedDefaultFolder":

The operation failed because of a registry or installation problem. Restart Outlook and try again. If the problem persists, reinstall.

I have a seperate application running on the same production PC that uses Microsoft.Office.Outlook.Interop to convert .MSG files to .PDF and that runs without issue.

The only difference that I can think of is that my development PC is Windows XP and the production PC is Windows 7.

Any thoughts would be greatly appreciated!

Thanks!


这篇关于Exchange WebServices将消息另存为msg文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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