Blue Theme Orange Theme Green Theme Red Theme
 
6 Months Free & No Setup Fees ASP.NET Hosting!
Home | Forums | Videos | Photos | Blogs | Beginners | Advertise with Us
 | Consulting  
Submit an Article Submit a Blog 
 Jump to
Skip Navigation Links
TechnologyExpand Technology
WebsiteExpand Website
Team Foundation Server Hosting
Search :       Advanced Search »
Home » Office and VB.NET » Automate Send & Receive in Outlook

Automate Send & Receive in Outlook

In this article we will take the privilege of outlook and make it to send & receive the mail automatically using VB.Net.

Page Views : 11711
Downloads : 0
Rating :
 Rate it
Level : Intermediate
   Print Read/Post comments Post a comment  Similar Articles  
   Email to a friend  Bookmark  Author's other articles  
 
Team Foundation Server Hosting
Become a Sponsor
 Tag Cloud
 Latest Jobs
More ... 
 Latest Interview Questions
More ... 

Introduction:

 

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

 

Summary:

         

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()

        Try

            'Microsoft.Office.Interop.Outlook._Application

            ' 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"),

             outlook._NameSpace)

            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")

            Console.WriteLine(oCmdBar.Name)

            Dim oBarCrls As office.CommandBarControls = oCmdBar.Controls

            Console.WriteLine(oBarCrls.Count)

            Dim oBP As office.CommandBarPopup

 

            'Get the Tools menu.

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

            office.CommandBarPopup)

            Console.WriteLine(oBPop.Caption)

            oBarCrls = oBPop.Controls

            Dim oBn As office.CommandBarControl

 

            'Get the Send/Receive menu.

            Dim oSendReceive As office.CommandBarPopup =  

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

            Console.WriteLine(oSendReceive.Caption)

 

            '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)

 

            Console.WriteLine(oSendReceiveAll.Caption)

 

            'Do the action.

            oSendReceiveAll.Execute()

 

            'Log off.

            oNS.Logoff()

 

            '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

 

Conclusion:

 

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 vb.net coding.

Comment Request!
Thank you for reading this post. Please post your feedback, question, or comments about this post Here.
Login to add your contents and source code to this article
 [Top] Rate this article
 
 About the author
 
Sridhar Manoharan
Looking for C# Consulting?
C# Consulting is founded in 2002 by the founders of C# Corner. Unlike a traditional consulting company, our consultants are well-known experts in .NET and many of them are MVPs, authors, and trainers. We specialize in Microsoft .NET development and utilize Agile Development and Extreme Programming practices to provide fast pace quick turnaround results. Our software development model is a mix of Agile Development, traditional SDLC, and Waterfall models.
Click here to learn more about C# Consulting.
 
Introducing MaxV - one click. infinite control. Hyper-V Hosting from MaximumASP.
Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
Dynamic PDF
ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
Discover the top 5 tips for understanding .NET
Ricky Leeks presents the top 5 tips for understanding .NET Interoperability. Learn more.
Nevron Chart for .NET 2010.1 Now Available
The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
ASP.NET 4 Hosting
Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites – Click Here!
 
 Post a Feedback, Comment, or Question about this article
Subject:
Comment:
Mindcracker MVP Summit 2012
Become a Sponsor
 Comments
Doubt by ram On August 24, 2007
Hi, Iam using the following code for the "subject alert" , it is working fine for that session only, whenever restarting outlook, iam losing the code..........., can u help me out in the issue like how can i save that code for the entire session in the out look...... Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean) Dim strSubject As String strSubject = Item.Subject If Len(strSubject) = 0 Then Prompt$ = "Subject is Empty. Are you sure you want to send the Mail?" If MsgBox(Prompt$, vbYesNo + vbQuestion + vbMsgBoxSetForeground, "Check for Subject") = vbNo Then Cancel = True End If End If End Sub Thanks & regards, R.Mohan.
Reply | Email | Modify 
ofolder by tharpa On November 15, 2007
Visual Studio is not recognizing ofolder. Any suggestions?
Reply | Email | Modify 

 © 2012  contents copyright of their authors. Rest everything copyright Mindcracker. All rights reserved.