Automate Send & Receive in Outlook using VB.NET



This article clearly explains about how to automate or force the Send/Receive event in the outlook using This code can be used as a service and made to automate the Send/Receive event in the outlook for a regular interval.




The following steps will help us to create the application.


Step 1: Start Microsoft Visual Studio .NET.


Step 2: On the File menu, click New, and then click Project.


Step 3: Click Visual Basic Projects under Project Types, and then click Console Application under Templates. By default, Module1.vb is created.


Step 4: Add a reference to the Microsoft Outlook 10.0/11.0 Object Library. To do this, follow these steps:


  • On the Project menu, click Add Reference.
  • On the COM tab, click Microsoft Outlook 10.0/11.0 Object Library, and then click Select.
  • Click OK in the Add References dialog box to accept your selections. If you are prompted to generate wrappers for the library that you selected, click Yes.


Step 5: In the Code window, replace all of the code with the following:


Automate Send & Receive:


Imports System.Reflectio

Module Module1

Sub Main()



' Create an Outlook application.

Dim oApp As Outlook._Application = New Outlook.Application

' Get the MAPI NameSpace and Logon values.

Dim oNS As Outlook._NameSpace = CType(oApp.GetNamespace("MAPI"),


oNS.Logon(Missing.Value, Missing.Value, True, True)


'Get Explorer for the folder.

Dim oExp As Outlook._Explorer = oFolder.GetExplorer(False)


'Get the Menu bar.

Dim oCmdBars As office._CommandBars = oExp.CommandBars

Dim oCmdBar As office.CommandBar = oCmdBars("Menu Bar")


Dim oBarCrls As office.CommandBarControls = oCmdBar.Controls


Dim oBP As office.CommandBarPopup


'Get the Tools menu.

Dim oBPop As office.CommandBarPopup = CType(oBarCrls("Tools"),



oBarCrls = oBPop.Controls

Dim oBn As office.CommandBarControl


'Get the Send/Receive menu.

Dim oSendReceive As office.CommandBarPopup =

CType(oBarCrls("Send/Receive"), office.CommandBarPopup)



'Get the Send and Receive All menu.

oBarCrls = oSendReceive.Controls


'TO DO: If you use the Microsoft Outlook 10.0 Object Library,

'uncomment the following line.


'Dim oSendReceiveAll As Office.CommandBarControl =

'CType(oBarCrls("Send and Receive All"), Office.CommandBarControl)


'TO DO: If you use the Microsoft Outlook 11.0 Object Library,

' uncomment the following line.


'Dim oSendReceiveAll As Office.CommandBarControl =

' CType(oBarCrls("Send/Receive All"), Office.CommandBarControl)




'Do the action.



'Log off.



'Clean up.

oApp = Nothing

oNS = Nothing

oFolder = Nothing

oExp = Nothing

Catch e As Exception

Console.WriteLine("{0} Exception caught.", e)

End Try

End Sub


Step 6: Press F5 to build and run the program.


Step 7: Verify that the Contact Detail (contact detail in outlook format) is received through mail




This process even can be achieved by inbuilt schedule option of the Microsoft Outlook. If it was done it needs the outlook to be open but in our case its not needed and the same is achieved through the coding.

Up Next
    Ebook Download
    View all
    View all