之所以使用 MAPI,起初是为了取得系统的地址本以及结局上面第五节的问题2。
MAPI 相对于 Simple MAPI 要复杂的多。具体的使用方法可以参考 MSDN 文档“Handling an Outgoing Message”、“Handling the Address Book”以及“Sending or Receiving a Message on Demand”。这里只对几个关键的问题加以说明。
1、仅 Microsoft Outloook 比较好地支持了 MAPI,包括 Microsoft Outlook Express 均不支持 MAPI 调用。
2、MAPI 看似复杂,实际上,他的几乎所有数据存储和访问,都是一个关键的接口:IMAPITable。也就是说,所有的数据存储都是类似表的结构。搞清楚了这个,再编码就很顺了,不管是发送接收邮件还是操作地址本,存取数据流程都是搞表格。:P
3、上面的问题2仍然不能解决。根据“Sending or Receiving a Message on Demand”的说明,关键的是 FlushQueues() 函数,但是我尝试了各种方法,均无法使它生效。若干天对自己的痛苦反思之后,终于怀疑微软有问题。于是我在网上翻出了一篇问答,中间有这么一段话:
“The IMAPIStatus::FlushQueues method appears not to work at all any more. Call it and you'll get a successful return code but nothing happens as a result. ” --Pete Maclean.
于是我彻底放弃。:(
http://msdn2.microsoft.com/en-us/library/dww0e04a(VS.80).aspx
To add a reference to a primary interop assembly
1.
Open your Visual Studio Tools for Office project and select the project name in Solution Explorer.
2.
Open the Project menu and click Add Reference.
3.
Under the COM tab, select the component you want in the Component Name list. For a list of Microsoft Office primary interop assemblies and corresponding component names, see Office Primary Interop Assemblies.
4.
Click OK.
The component name appears in the References folder of Solution Explorer.
If the primary interop assembly is not installed in the global assembly cache or is not accessible, Visual Studio generates an interop assembly for the project that might not work fully in all cases. When this happens, Visual Studio creates the assembly in the project folder instead of in the global assembly cache. You can find the location of the assembly by checking the Path property of the assembly in the Visual Studio Properties window. For more information, see "Assembly Cannot Be Initialized" in Troubleshooting in Office at Run Time.