Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VSTO - Outlook 2007 - Display form before send message?

Tags:

I'm new to Outlook add-in programming and not sure if this is possible:

I want to display a pop-up form (or selection) and ask for user input at the time they click Send. Basically, whenever they send out an email (New or Reply), they will be asked to select a value in a dropdown box (list items from a SQL database, preferrably). Base on their selection, a text message will be appended to the mail's subject.

I did my research and it looks like I should use Form Regions but I'm not sure how can I display a popup/extra form when user click Send. Also, it looks like Form Regions can be used to extend/replace current VIEW mail form but can I use it for CREATE NEW form?

Thanks for everybody's time.

like image 208
Eric Nguyen Avatar asked Nov 16 '09 05:11

Eric Nguyen


1 Answers

You can probably add the Item Send event handler in the ThisAddIn Internal Startup method and then in the Item Send Event, call the custom form (a windows form). In the below sample I call a custom windows form as modal dialog before the email item is send and after the send button is clicked.

private void InternalStartup()
{
    this.Application.ItemSend += new ApplicationEvents_11_ItemSendEventHandler(Application_ItemSend);
}

void Application_ItemSend(object Item, ref bool Cancel)
{
    if (Item is Microsoft.Office.Interop.Outlook.MailItem)
    {
        Microsoft.Office.Interop.Outlook.MailItem currentItem = Item as Microsoft.Office.Interop.Outlook.MailItem; 
        Cancel = true;
        Forms frmProject = new ProjectForm();;

        DialogResult dlgResult = frmProject.ShowDialog();

        if (dlgResult == DialogResult.OK) 
            System.Windows.Forms.SendKeys.Send("%S"); //If dialog result is OK, save and send the email item
        else
            Cancel = false; 

        currentItem.Save();
        currentItem = null;
    }
}
like image 196
yenkay Avatar answered Oct 10 '22 01:10

yenkay