Reputation: 417
I have a Outlook AddIn that shows a dialog every time a user sends a message.
I am opening the dialog and getting the message information on onItemSend event. This is working as expected: Once the message is sent, it opens a dialog, with some information such as recipients, subject, etc.
The problem is when the user keeps Outlook opened and send a message from another source, such as phone or tablet. After the user sends the message, the opened Outlook will display the dialog, even if it was not sent from that instance.
For instance, there was a user that has the addin installed at his home and office. He kept his home Outlook opened and after a busy day at work, sending several messages and displaying the dialogs, he checks his outlook at home. It will be several opened dialogs, regarding the messages he sent during the day.
Is there a way to restrict the dialogs? Kind of open the dialog where the user is sending the message from? This way the user will not have any dialog in any other opened outlook...
Thanks
EDIT
Just checked my code and there was a misunderstand (of my part off course). I removed some code from the methods, just to be easier to read...
There are two event handlers in the code:
Outlook.Folder sentbox;
Outlook.Items myOlItems = null;
this.itemsendhndler = newicrosoft.Office.Interop.Outlook.ApplicationEvents_11_ItemSendEventHandler(Application_ItemSend);
this.Application.ItemSend += itemsendhndler;
this.hndler = new Outlook.ItemsEvents_ItemAddEventHandler(Application_ItemAdd);
sentbox = this.Application.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderSentMail) as Outlook.Folder;
myOlItems = sentbox.Items;
myOlItems.ItemAdd += this.hndler;
Then, in Application_ItemAdd there is the onItemSend method, that I thought it was the Application_ItemSend...
void Application_ItemAdd(object Item)
{
this.onItemSend(Item);
}
private void Application_ItemSend(object item, ref bool Cancel)
{
Outlook.MailItem mail = item as MailItem;
if (mail == null)
return;
//Make sure this is a E-mail message
if (string.Compare(OutlookItemHelper.GetMessageClass(mail), "IPM.Note") != 0)
return;
mail.DeleteAfterSubmit = false;
Outlook.Folder sentFolder = this.Application.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderSentMail) as Outlook.Folder;
if (sentFolder != null)
mail.SaveSentMessageFolder = sentFolder; // override the default sent items location
Cancel = false;
}
private void onItemSend(object Item)
{
Outlook.MailItem itm = null;
itm = (Outlook.MailItem)Item;
using (ExampleDialog dlg = new ExampleDialog())
{
//code after actions...
}
}
Anyway, the dialog is not being opened in Application_ItemSend event. My bad guys...I learnt something new today!
Thanks guys and I apologize for the newbie question...
Upvotes: 0
Views: 263
Reputation: 66215
Are you sure? Application.ItemSend will only fire on the instance of Outlook that actually sends the message. Items.ItemAdd event on the Sent Items folder on the other hand will fire in each instance of Outlook. Is that what your code is doing?
Upvotes: 1