开发者

Perform programmatic Send/Receive on Outlook that will work for 2003, 2007 and 2010

开发者 https://www.devze.com 2023-02-12 01:11 出处:网络
I am trying to write some basic Outlook code that should support Outlook 2003, 2007 and 2010. I am working with Outlook 2010 PIAs. Everything works except a method that should cause Outlook to perform

I am trying to write some basic Outlook code that should support Outlook 2003, 2007 and 2010. I am working with Outlook 2010 PIAs. Everything works except a method that should cause Outlook to perform Send/Receive. I have tried a couple of options:

  1. Call Namespace.SendAndReceive method (works on Outlook 2007 and 2010, fails on Outlook 2003 with AccessViolationException).
  2. Iterate through Namespace.SyncObjects and calling their start method (works in Outlook 2003 and 2007 and fails on Outlook 2010 with RPC server is not available when I try to call GetNamespace("MAPI") on my application object)

Ca开发者_如何学编程n someone propose a method that should work consistently on all versions?


I believe that SendAndReceive() was added as a convenience method in 2007 so that won't work in 2003 as you found out. According to the 2010 documentation you should still be able to use SyncObjects collection and still call Start(). Is it possible that you're 2010 installation has a bad mail/news/whatever profile? Is Start() failing on a specific SyncObject?

The other solution which you probably already thought of is to use SyncObjects for 2003 and SendAndReceive() for future versions.


//First Register the Sync Event     
if (oApp.Session.SyncObjects.Count > 0)
{
    _syncObj = oApp.Session.SyncObjects[1];
    _syncObj.SyncEnd += new Outlook.SyncObjectEvents_SyncEndEventHandler(_syncObj_SyncEnd);
    _syncObj.Start();
}
void _syncObj_SyncEnd()
{
    _syncObj.Stop();
}
0

精彩评论

暂无评论...
验证码 换一张
取 消