Click here to Skip to main content
Click here to Skip to main content

Outlook Add-in: Set the time for your draft mails, for sending the mails at particular time in Microsoft Outlook 2003

, 11 Aug 2006
Rate this:
Please Sign up or sign in to vote.
This Outlook add-in will create a Command Bar button in the Standard Tool buttons collection. This utility will automatically send the draft mails.

Sample Image - OutlookAdd-in_small.jpg

Introduction

This utility will set the time for your draft mails. And will automatically send the mails.

This article will give you an basic idea how to create an add-in for the Microsoft applications.

Steps to create a add-in project in VS.Net 2003.

  1. Start a new project by choosing File, New Project, Other Projects Extensibility Projects, Shared Add-In. Click OK. Click Next at the Welcome screen.

  2. Page 1 of 5 asks you to select a programming language C#, VB or VC++. Select C#. Click Next.

  3. On Page 2 of 5 Select an Application Host, Select Microsoft outlook. Click Next.

  4. On Page 3 of 5 name the add-in MyAddin and enter a description; for example, My First Add-In. Click Next..

  5. On Page 4 of 5 we want to indicate that the add-in can be invoked from the Tools menu, the add-in should load when the host loads, and the add-in should be available to all users. (Check all check boxes.) Click Next.

  6. On Page 5 of 5, review the Summary information, and if it is correct, click Finish.

With the above steps 2 projects will be created. One is class library and the other is Set up project. The output of setup will be used to install the Add-in.

The Class library will consist of Connect class which inherits Object class and implements

Extensibility.IDTExtensibility2. The method definition for all the methods in IDTExtensibility2 will already be present with the summary. These methods can be used to implement your add-in. Following are the IDTExtensibility2 Methods:

Public

OnAddInsUpdate

Occurs whenever an add-in is loaded or unloaded from the Visual Studio integrated development environment (IDE).  

Public

OnBeginShutdown

Occurs whenever the Visual Studio integrated development environment (IDE) shuts down while an add-in is running.  

Public

OnConnection

Occurs whenever an add-in is loaded into Visual Studio.  

Public

OnDisconnection

Occurs whenever an add-in is unloaded from Visual Studio.  

Public

OnStartupComplete

Occurs whenever an add-in, which is set to load when Visual Studio starts, loads.  

I have used OnStartupComplete(ref System.Array custom) method to create a CommandBarButton. The CommandBarButton is then added to the Standard CommandBar. 

Following is the code to create a CommandBarButton:

private Microsoft.Office.Core.CommandBarButton automateButton;
// In case the button was not deleted, use the exiting one.
try
{
    automateButton = (CommandBarButton)
      oStandardBar.Controls["Automate Mails"];
}
catch(Exception)
{
    object omissing = System.Reflection.Missing.Value ;
    automateButton = (CommandBarButton) oStandardBar.Controls.Add(1, 
                      omissing , omissing , omissing , omissing);
    automateButton.Caption = "Automate Mails";
    automateButton.Style = MsoButtonStyle.msoButtonCaption;
}
automateButton.OnAction = "!<MyCOMAddin.Connect>";
automateButton.Visible = true;
automateButton.Click += new 
  Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(
  this.AutomateButton_Click);

This button is added to the Standard CommandBar. Following is the code to get the Standard CommandBar from the Outlook object.

CommandBars oCommandBars;
CommandBar oStandardBar;
try
{
    oCommandBars = (CommandBars)
      applicationObject.GetType().InvokeMember("CommandBars", 
      BindingFlags.GetProperty , null, applicationObject, null);
}
catch(Exception)
{
    // Outlook has the CommandBars collection
    // on the Explorer object.
    object oActiveExplorer;
    oActiveExplorer= 
      applicationObject.GetType().InvokeMember(
      "ActiveExplorer",BindingFlags.GetProperty, 
      null,applicationObject,null);
    oCommandBars= (CommandBars)
      oActiveExplorer.GetType().InvokeMember("CommandBars", 
      BindingFlags.GetProperty, null, oActiveExplorer, null);
}
// Set up a custom button on the "Standard" commandbar.
try
{
    oStandardBar = oCommandBars["Standard"]; 
}
catch(Exception)
{
    // Access names its main toolbar Database.
    oStandardBar = oCommandBars["Database"]; 
}

The Button click handler will open up the Automate window. Where the user can set the time for all the Draft messages.

private void AutomateButton_Click(Microsoft.Office.Core.CommandBarButton 
     cmdBarbutton, ref bool cancel)
{
  mailAutomationObject.oApp = (Outlook.Application)applicationObject;
  mailAutomationObject.ShowDialog();
}

Mail Automation Window

Double Click any Draft mail in Automation Window will open up a window where user can set the time.

Sample screenshot

The mails will be send automatically at the selected time.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Lalit Singh Sisodia
Web Developer
India India
Dedicated to my wife Smita Lalit Sisodia and daughter Bhavya Sisodia

Comments and Discussions

 
GeneralA simple and elegant example showing how to write add-on. PinmemberRajganesh Mountbatton6-Jul-09 22:51 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web04 | 2.8.140709.1 | Last Updated 11 Aug 2006
Article Copyright 2006 by Lalit Singh Sisodia
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid