How to use the Microsoft Outlook Object Library to force a Send/Receive action by using Visual Basic .NET
Symptoms
This article describes how to use the Microsoft Outlook 2002 Object Library or the Microsoft Office Outlook 2003 Object Library to force a Send/Receive action by using Microsoft Visual Basic .NET.
Resolution
To use the Outlook 2002 Object Library or the Outlook 2003 Object Library to force a Send/Receive action in a Visual Basic .NET project, follow these steps: Start Microsoft Visual Studio .NET. On the File menu, point to New, and then click Project. Under Project Types, click Visual Basic Projects.Under Templates, click Console Application, and then click OK.
By default, Module1.vb is created.Add a reference to either the Outlook 2002 Object Library or the Outlook 2003 Object Library: On the Project menu, click Add Reference.On the COM tab, click Microsoft Outlook 11.0 Object Library if you are using Outlook 2003, or click Microsoft Outlook 10.0 Object Library if you are using Outlook 2002, and then click Select. In the Add References dialog box, click OK to accept your selections. If you receive a prompt to generate wrappers for the libraries that you selected, click Yes.In the code window, replace all the code with:
‘TO DO: If you use the Microsoft Outlook 11.0 Object Library, uncomment the following line.’Imports Outlook = Microsoft.Office.Interop.OutlookModule Module1Sub Main()’ Create an Outlook application.Dim oApp As Outlook._Application = New Outlook.Application’ Create the name space.Dim oNS As Outlook._NameSpace = oApp.GetNamespace(“mapi”)Dim oSyncs As Outlook.SyncObjectsDim oSync As Outlook.SyncObjectTry’ Reference SyncObjects.oSyncs = oNS.SyncObjectsoSync = oSyncs.Item(“All Accounts”)’ Send and receive.oSync.Start()Catch ex As ExceptionConsole.WriteLine(ex.Message)End Try’ Clean up.oSync = NothingoSyncs = NothingoNS = NothingoApp = NothingEnd SubEnd ModulePress F5 to build and run the program.

Leave a Reply