如何通过 API 将 MSG/EML 电子邮件文件导入 Outlook? [英] How to import MSG/EML email files into Outlook via the API?

查看:88
本文介绍了如何通过 API 将 MSG/EML 电子邮件文件导入 Outlook?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个充满 EML/MSG 电子邮件数据文件的目录层次结构.这些文件可以一次一个导入到 MS Outlook 2010(桌面版)中,但我正在寻找一种方法来自动执行此操作.我需要将每个文件夹创建为 Outlook 文件夹,并将电子邮件数据文件导入到这些 Outlook 文件夹中.任何知道 Outlook 2010 API 允许创建文件夹 &导入文件?

I have a directory hierarchy full of EML/MSG email data files. These files can be imported into MS Outlook 2010 (desktop version) one at a time, but I am looking for a way to automate this. I need to create each folder as an Outlook folder, and import email datafiles into these Outlook folders. Anyone aware of an Outlook 2010 API that allows for creating folders & importing files?

推荐答案

要在 Outlook 中创建新文件夹,请使用 MAPIFolder.Folders.Add.

To create new folders in Outlook, use MAPIFolder.Folders.Add.

Outlook 对象模型不直接支持导入 EML 或 MSG 文件(或任何其他与此相关的文件).

Outlook Object Model does not directly support importing EML or MSG files (or any other files for that matter).

对于 MSG 文件,您可以

For MSG files you can

  1. 使用扩展 MAPI(仅 C++ 或 Delphi)和 OpenIMsgOnIStg 函数打开一个 MSG 文件.然后,您可以在目标文件夹中创建一条新消息并使用 IMesage.CopyTo 复制属性(请记住,独立的 MSG 文件无法正确处理 CopyTo 中的命名属性)或一次读取一个属性并将它们设置在目标上消息明确.

  1. Use Extended MAPI (C++ or Delphi oinly) and the OpenIMsgOnIStg function to open an MSG file. You can then create a new message in the target folder and copy properties either using IMesage.CopyTo (keep in mind that standalone MSG files do not correctly process named properties in CopyTo) or read the properties one at a time and set them on the target message explicitly.

Outlook 对象模型可以使用 Application.CreateItemFromTemplate(它将在未发送状态下创建)和 Namespace.OpenSharedItem 打开 MSG 文件.然后您可以将邮件 (MailItem.Move) 移动到目标文件夹中

Outlook Object Model can open MSG files using Application.CreateItemFromTemplate (it will be created in an unsent state) and using Namespace.OpenSharedItem. You can then move the message (MailItem.Move) into the target folder

对于 EML 文件,您可以

For the EML files, you can

  1. 使用扩展 MAPI(仅限 C++ 或 Delphi)和内置 Outlook 界面(IComverterSession).您可以在 OutlookSpy(单击 IConverterSession 按钮)中使用该界面.

  1. Use Extended MAPI (C++ or Delphi only) and the built-in Outlook interface (IComverterSession). You can play with that interface in OutlookSpy (click IConverterSession button).

Outlook 对象模型根本不支持 EML 文件.您能做的最好的事情是创建自己的解析器并将 EML 文件一次复制到 Outlook 中的一个 MIME 标头/部分.

Outlook Object Model does not support EML files at all. The best you can do is create your own parser and copy the EML file into Outlook one MIME header/part at a time.

如果使用 Redemption 是一种选择,您可以使用 RDOMail.Import 方法 - 它导入 MSG (olMsg) 和 EML (olRfc822) 文件(以及一些其他格式)).

If using Redemption is an option, you can use RDOMail.Import method - it imports MSG (olMsg) and EML (olRfc822) files (as well as a few other formats).

  set Session = CreateObject("Redemption.RDOSession")
  Session.MAPIOBJECT = Application.Session.MAPIOBJECT '//or you can call Logon
  set Inbox = Session.GetDefaultFolder(olFolderInbox)
  set Msg = Inbox.Items.Add
  Msg.Sent = true '//since Import does not copy this property
  Msg.Import("c:\temp\test.eml", 1024) ' //1024 is olRfc822
  Msg.Save

这篇关于如何通过 API 将 MSG/EML 电子邮件文件导入 Outlook?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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