Outlook Programming Series # 13 : Programmatic equivalent for Outlook UI's Send/Receive


                    Le Café Central de
Deva              

                                 
                                 ..... Deva blogs!!




 

 

Outlook Programming Series # 13 : Programmatic equivalent for Outlook UI's Send/Receive

  • Comments 1

Whenever we work with Outlook 2007 UI, we click either "Send/Receive button" or press "F9" to send and receive emails. In couple of our cases we use to do programmatically you can make use of Outlook Object Model's (OOM) SendAndReceive method. You need to know that calling the SendAndReceive method is synchronous only.

Syntax: expression.SendAndReceive(showProgressDialog)

Here, showProgressDialog - Indicates whether the Outlook Send/Receive Progress dialog box should be displayed, regardless of user settings

Note:

  • SendAndReceive provides the programmatic equivalent to the Send/Receive All command that is available when you click Tools and then Send/Receive.
  • If you do not need to synchronize all objects, you can use the SyncObjects collection object to select specific objects. For more information, see NameSpace.SyncObjects.
  • All accounts defined in the current profile are used in Send/Receive All.
  • If an online connection is required to perform the Send/Receive All, then the connection is made according to user preferences.

Using with Outlook Object Model & Visual Basic 6:

Use NameSpace.SendAndReceive Method. Initiates immediate delivery of all undelivered messages submitted in the current session, and immediate receipt of mail for all accounts in the current profile.

Using in .Net environment & Outlook interop:

Use NameSpaceClass.SendAndReceive Method (Microsoft.Office.Interop.Outlook). The types and members of the Microsoft.Office.Interop.Outlook namespace provide support for interoperability between the COM object model of Microsoft Office Outlook 2007 and managed applications that automate Outlook.

This is a .NET class or a member of a .NET class created when processing a COM coclass that is required by managed code for interoperability with the corresponding COM object. Use this class only when you have to access an earlier event in this class that has been subsequently extended in a later version of Outlook. Otherwise, use the .NET interface derived from the COM coclass.

Code snippet (used in the add-in):

C#

   1:  public virtual void _NameSpace.SendAndReceive (
   2:      [InAttribute] bool showProgressDialog
   3:  )

then we need to use the SyncObject,

   1:  //trap the SyncObject.SyncStart Event 
   2:    this.Application.Session.SyncObjects[1].SyncStart += new Microsoft.Office.Interop.Outlook.SyncObjectEvents_SyncStartEventHandler(ThisAddIn_SyncStart);
   3:   
   4:  //finally don't forget to trap the SyncObject.SyncEnd Event 
   5:  this.Application.Session.SyncObjects[1].SyncEnd += new Microsoft.Office.Interop.Outlook.SyncObjectEvents_SyncEndEventHandler(ThisAddIn_SyncEnd);
   6:   

Visual Basic:

   1:  Dim instance As NameSpaceClass
   2:  Dim showProgressDialog As Boolean
   3:   
   4:  CType(instance, _NameSpace).SendAndReceive(showProgressDialog)


Reference(s):

http://msdn.microsoft.com/en-us/library/microsoft.office.interop.outlook.namespaceclass.sendandreceive.aspx
http://msdn.microsoft.com/en-us/library/microsoft.office.interop.outlook.syncobjectevents_event_members.aspx

  • Wonderful stuff & good explanation!! I never thought such thing existed with Outlook Object Model.

Page 1 of 1 (1 items)
Blog - Post Feedback Form(CAPTCHA)
Leave a Comment
  • Post