Reputation: 154
I generate a message and open it for the user, using Microsoft.Office.Interop.Outlook. When a user sends the message in Outlook I want to capture this event. Not as discussed in this SO tread:
capture the Outlook 2013 Send event
where I capture all sent emails, not only generated.
public static MailItem CreateMail()
{
Application outlook = new Application();
MailItem mailItem = outlook.CreateItem(OlItemType.olMailItem);
// set recipients, body, ect..
mailItem.Send += MailItemSendedHandler;
Inspector inspector = mailItem.GetInspector;
inspector.Activate();
return mailItem;
}
static void MailItemSendedHandler(ref bool isSended)
{
}
MailItem has a Send()
method and a Send
Event. When I subscribe I get the error:
Cannot assign to "Send", because it is a method group.
How can I capture the Send
event for my MailItem?
Upvotes: 1
Views: 2374
Reputation: 154
MailItem
is an interface which inherits from interfaces _MailItem
and ItemEvents_10_Event
. Both of them have Send
. (In _MailItem it is a method, in ItemEvents_10_Events it is an event). I think we have a conflict, and need to clearly define which Send
we want to use.
((ItemEvents_10_Event)mailItem).Send += new ItemEvents_10_SendEventHandler(MailItemSendedHandler);
static void MailItemSendedHandler(ref bool isSended)
{
}
Upvotes: 3