How to use the Microsoft Outlook Object Library to force a Send/Receive action by using Visual Basic .NET

Относится к
This article was previously published under Q313793

SUMMARY

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.

MORE INFORMATION

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:
  1. Start Microsoft Visual Studio .NET.
  2. On the File menu, point to New, and then click Project.
  3. Under Project Types, click Visual Basic Projects.
  4. Under Templates, click Console Application, and then click OK.

    By default, Module1.vb is created.
  5. Add a reference to either the Outlook 2002 Object Library or the Outlook 2003 Object Library:
    1. On the Project menu, click Add Reference.
    2. 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.
    3. 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.
  6. 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 Module1    Sub 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.SyncObjects        Dim oSync As Outlook.SyncObject        Try            ' Reference SyncObjects.            oSyncs = oNS.SyncObjects            oSync = oSyncs.Item("All Accounts")            ' Send and receive.            oSync.Start()        Catch ex As Exception            Console.WriteLine(ex.Message)        End Try        ' Clean up.        oSync = Nothing        oSyncs = Nothing        oNS = Nothing        oApp = Nothing    End SubEnd Module
  7. Press F5 to build and run the program.

The information in this article applies to:


Реклама