Outlook ItemSend event

A

Andy Bates

Hi -

I am developing an application that needs to automate Microsoft Outlook and
I need to capture the ItemSend event. The PC I'm developing with has Outlook
2003 on; the problem I have is I need to make the code work with Outlook XP
(i.e. 2002)!

The code to add the event is currently:

oOutlook.ItemSend += new Outlook.ApplicationEvents_11_ItemSendEventHandler
(oOutlook_ItemSend);

This works fine for Outlook 2003, but causes an 80040200 exception when used
with a computer running Outlook XP!

Changing the above to:

oOutlook.ItemSend += new Outlook.ApplicationEvents_10_ItemSendEventHandler
(oOutlook_ItemSend);

Causes a compilation error (cannot convert to
ApplicationEvents_11_ItemSendEventHandler).

I've also tried:

oOutlook.ItemSend += new Outlook.ApplicationEvents_ItemSendEventHandler
(oOutlook_ItemSend);

With essentially the same error as above being generated.

Can anyone shed any light on what I need to do to create an event that will
work with Outlook 2003 and XP?

TIA

- Andy
 
J

Jay B. Harlow [MVP - Outlook]

Andy,
I have not really done any cross version Outlook in .NET yet.

I believe you need to use the ApplicationEvents_10 events instead of the
ApplicationEvents_11 events.

The following site provides a number of articles on using Outlook from .NET.

http://www.microeye.com/resources/res_outlookvsnet.htm

Have you tried?
oOutlook.ApplicationEvents_10_ItemSend += new Outlook.ApplicationEvents_10_ItemSendEventHandler
(oOutlook_ItemSend);

Again I do not have both versions loaded to try the above.

Hope this helps
Jay
 
J

Jay B. Harlow [MVP - Outlook]

Andy,
In addition to my other post, I am checking with some others for further
information or confirmation on my answer.

Hope this helps
Jay
 
J

Jeffrey Tan[MSFT]

Hi Andy,

I can succeed trap the ItemSend event through the 2 ways below:

//Add the reference of "Microsoft Outlook 10.0 Object Library" first.
private void button2_Click(object sender, System.EventArgs e)
{
Outlook.ApplicationClass obj=new Outlook.ApplicationClass();
obj.ItemSend+=new
Outlook.ApplicationEvents_10_ItemSendEventHandler(obj_ItemSend);
obj.ApplicationEvents_Event_ItemSend+=new
Outlook.ApplicationEvents_ItemSendEventHandler(obj_ItemSend);
}

private void obj_ItemSend(object sender,ref bool arg)
{
MessageBox.Show("ItemSent");
}

The ItemSent messagebox will show 2 times, which means that these 2
approaches both work.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
M

Mike Belshe

I'm working on a similar problem.

I think the class you want to use is an Outlook.ApplicationClass rather
than the Outlook.Application.

The Outlook.Application object is specific to the library you
referenced. If you are referencing the XP library, you'll get XP
objects, which have _10_ in them. If you use the 2003 library, you'll
get 2003 objects, which have the _11_ in them. Unfortunately, these
libraries are NOT backward compatible, so when you go to run on older
versions of outlook, your application will not work.

There is an Outlook.ApplicationClass object which has generic event
handlers which (I think) are supposed to work across versions. Instead
of using the Outlook.Application.ItemSend event, you'll use the
Outlook.ApplicationClass.ApplicationEvents_Event_ItemSend event.

But - the caveat! For me (and this is where I am stuck), I can't get
the ApplicationClass object. If you run as Outlook automation, I think
you can just create your own:
Outlook.ApplicationClass foo = new Outlook.ApplicationClass();

but, if you are running as an outlook add-in (which I am), this whole
thing doesn't seem to work. (You get a Invalid Cast exception when you
try). I'm referencing the Outlook 10 libraries. I'm also finding that
when running as an Outlook Add-In, even if you do use the ItemSend event
(rather than the cross-version event handler), setting the Cancel flag
doesn't work.

Hope this helps. If anyone has any ideas on my problem, that would be
great!!!

Thanks,
Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top