Sending Mail Item

Add-in Express™ Support Service
That's what is more important than anything else

Sending Mail Item
 
nistech




Posts: 30
Joined: 2005-09-04
I have an inspector command bar on new mail items, the inspector has a button. 2 questions.

1) Is there a way to just place my button next to the send rather than using my own inspector?

2) When my button is pressed I run the following code. If this code is ran Outlook won't close anymore. If I start Outlook and send email, but don't send it with my button then Outlook does close properly. It's like my code is holding up resources and not allowing outlook.exe to actually close. Here is the code:

object currentItem = null;
Outlook.MailItem mail = null;

Outlook._Inspector inspector = OutlookApp.ActiveInspector();
if (inspector != null)
{
try
{
currentItem = inspector.CurrentItem;
if (currentItem is Outlook.MailItem)
{
mail = currentItem as Outlook.MailItem;
mail.Subject = "New subject";
mail.Body = "New Body";
mail.Send();
}
}
finally
{
if (currentItem != null)
Marshal.ReleaseComObject(currentItem);
Marshal.ReleaseComObject(inspector);
}
}


Thanks!
Posted 07 Jun, 2006 17:30:26 Top
Eugene Starostin


Guest


1) Is there a way to just place my button next to the send rather than using my own inspector?


Please try AfterID = 2617 for your button and CommandBarName = "Standard" for your command bar.
Posted 07 Jun, 2006 18:43:24 Top
nistech




Posts: 30
Joined: 2005-09-04
Thanks, I'll try that.

On #2 I tried adding a mail.DeleteAfterSubmit = false; before the send and also mail = null; after the send. Outlook still hangs.
Posted 07 Jun, 2006 18:53:30 Top
nistech




Posts: 30
Joined: 2005-09-04
Please try AfterID = 2617 for your button and CommandBarName = "Standard" for your command bar.


That appears to put it after the question mark when reading existing mail and not anywhere on a new email.
Posted 07 Jun, 2006 19:06:28 Top
Eugene Starostin


Guest


You are rignt. The Send button in a new mail window has id = 5469. So, add two buttons and show the button with AfterID = 5469 for new mails and vice versa.

I used our http://www.add-in-express.com/downloads/controls-scanner.php
Posted 07 Jun, 2006 19:14:03 Top
Eugene Starostin


Guest


On #2.

Way 1. Below I will describe an empty example.

1. Set "Snandard" to CommandBarName of your command bar. It doesn't add a new command bar, it connects ADXolInspectorCommandBar to the Standard command bar with the Send button.

2. Add an ADXBuiltinControl (see the Add Built-in Control command of the add-in module).

3. Bind the added ADXBuiltinControl to your command bar (via the CommandBar property of ADXBuiltinControl).

4. Set ADXBuiltinControl.ID = 2617.

5. Handle the ADXBuiltinControl.Action event (VB):
Private Sub AdxBuiltInControl1_Action(ByVal sender As System.Object) Handles AdxBuiltInControl1.Action
Dim Item As Outlook.MailItem
Item = CType(OutlookApp.ActiveInspector.CurrentItem, Outlook.MailItem)
Item.Subject = "Test"
Item.Save()
End Sub

6. And voila. You have intercepted the Send button :-)

It works for 5469 and 2617. I have just tested on my VS2005 and Office 2003.
Posted 07 Jun, 2006 19:18:23 Top
Eugene Starostin


Guest


On #2.

Way 2 is to release your mail variable :-)

currentItem = inspector.CurrentItem;
if (currentItem is Outlook.MailItem)
{
mail = currentItem as Outlook.MailItem;
mail.Subject = "New subject";
mail.Body = "New Body";
Marshal.ReleaseComObject(mail); // <<<<<<<<<<<<<

}

I have tested this VS2005 and Office 2003. What VS and Office do you use?
Posted 07 Jun, 2006 19:45:19 Top
Eugene Starostin


Guest


Sorry, I accidentally deleted the mail.Send(); line.
Posted 07 Jun, 2006 19:50:52 Top
nistech




Posts: 30
Joined: 2005-09-04
Intercepting the Send button is very cool and could prove very useful down the road, but for now I need my button beside the send button.

I am running Outlook 2003 with VS 2005. If I release mail like that it works on a Save, but not on a Send.
Posted 07 Jun, 2006 20:36:05 Top
nistech




Posts: 30
Joined: 2005-09-04
Just with messing with it a little bit now I can't get any inspector command bar to show up. Even a new one. I even rolled back source code and can't get it to show up. Tried an unregister and register. Can Outlook get messed up?
Posted 07 Jun, 2006 21:13:32 Top