Bassem Murad

Hello,

im using VSTO SE and VS 2005 to create a plugin for outlook 2003. In the create new email inspector, i added a button. i want to send the email and perform another task. i was able to add the button to the inspector and perform some function, but i have no idea how to make that button send the email as well.

here is how the plugin looks like...

public Outlook.Inspectors openInspectors;

private Office.CommandBar helloCommandBar;

private Office.CommandBarButton helloCommandBarButton;

private void ThisAddIn_Startup(object sender, System.EventArgs e)

{

openInspectors = Application.Inspectors;

openInspectors.NewInspector += new Outlook.InspectorsEvents_NewInspectorEventHandler(

Inspectors_NewInspector);

}

private void Inspectors_NewInspector(Outlook.Inspector inspector)

{

helloCommandBar = inspector.CommandBars.Add(

"hello", Office.MsoBarPosition.msoBarRight,

Type.Missing, true);

if (helloCommandBar != null)

{

helloCommandBar.Visible = true;

}

helloCommandBarButton = ((Office.CommandBarButton)

(helloCommandBar.Controls.Add(

Office.MsoControlType.msoControlButton,

Type.Missing, Type.Missing, Type.Missing, true)));

helloCommandBarButton.Caption = "Say hello";

helloCommandBarButton.Visible = true;

helloCommandBarButton.Click += new _CommandBarButtonEvents_ClickEventHandler(helloCommandBarButton_Click); ;

}

void helloCommandBarButton_Click(CommandBarButton Ctrl, ref bool CancelDefault)

{

MessageBox.Show("Hello");

// after i show the message box, i need to send the email...

}

Thx Smile




Re: Visual Studio Tools for Office sending an email from inspector window..

Sue Mosher - Outlook MVP

At the moment when the user clicks the button, the item being sent is that displayed in the ActiveInspector window. THerefore, you should be able to call Application.ActiveInspector.CurrentItem to return the current message, then call its Send method.





Re: Visual Studio Tools for Office sending an email from inspector window..

Bassem Murad

i did that...but the problem is it doesnt validate To, CC, and BCC.




Re: Visual Studio Tools for Office sending an email from inspector window..

Bassem Murad

is there a way to validate them automatically like the send button does

i mean like if its empty or not and if the name written doesnt exist (so it shows add contact window)

thx






Re: Visual Studio Tools for Office sending an email from inspector window..

Sue Mosher - Outlook MVP

You should call MailItem.Recipients.ResolveAll and send the message only if ResolveAll returns True. Outlook does not provide a way to display the Select Recipient dialog to the user if a recipient can't be resolved. To do that, you need the third-party Outlook Redemption library.





Re: Visual Studio Tools for Office sending an email from inspector window..

Bassem Murad

still doesnt work Sad... i get this error "There must be at least one name or distribution list in the To, Cc, or Bcc box."

mailitem.To / CC/ and BCC are all null althought i did add some emial in the "To" feild..

also, resolve all returns true all the time...

here is the code

void helloCommandBarButton_Click(CommandBarButton Ctrl, ref bool CancelDefault)

{

Outlook.Inspector x= Application.ActiveInspector();

if (x.CurrentItem is Outlook.MailItem)

{

Outlook.MailItem m = (Outlook.MailItem)x.CurrentItem;

try

{

if (m.Recipients.ResolveAll())

m.Send();

}

catch (Exception e)

{ }

}

}

any ideas

thx






Re: Visual Studio Tools for Office sending an email from inspector window..

Sue Mosher - Outlook MVP

Did you add recipients programmatically or manually What does m.Recipients.Count return Does m.Subject indicate you have the correct item





Re: Visual Studio Tools for Office sending an email from inspector window..

Bassem Murad

count returns 0 and subject is null...

i set them in the inspector window and then click on the button (i mean in the outlook, not in the code)...this is what i dont understand. Why is the mailobject empty

P.S: my code is exactly like the first post and the previous one... Sad






Re: Visual Studio Tools for Office sending an email from inspector window..

Sue Mosher - Outlook MVP

I would suggest that you implement an Inspector wrapper class, such as that by Helmut at http://www.outlookcode.com/codedetail.aspx id=797 . You're going to need it anyway to handle multiple open Inspector windows, so you might as well try it now. I suspect it will solve your problem.