Outlook Events.

J

JIGNESH

Hi
I am a bit surprize that events mailItem.Open ,mailItem.Read and
mailItem.Unload does not have a std event signiture like (object, e ) as we
see everywhere in .net.

Anyways what i want to do when any mail is open for reading and then close
either by closing window or moving cursor to next mail item, i want to
retrive mail information like Subject, CC. Which events i should tap and if
there are no parameteres in the event then how do i retrieve mail information.

Regards
 
K

Ken Slovak - [MVP - Outlook]

Outlook is a COM application and provides COM events that are handled
through the Interop and a PIA. You will find the same situation with any COM
application.

You can handle the item.Close() and Inspector.Close() events. An Inspector
is the window used to display open Outlook items. You will probably be best
off handling both as using Next/Previous may not fire Inspector.Close(), and
in some situations the item.Close() event may not fire.

When you have the handle to the item, or from an Inspector event to
Inspector.CurrentItem, the item in the Inspector, you use the object model
for that item to get the various properties you want from the item. Use the
Object Browser to see what events, properties and methods are available for
any type of Outlook item.
 
J

JIGNESH

Hi Ken,

Thanks for your inputs.
When you double click any email item, it opens in new window, else on one
click, it opens mail in the right had side section , next to mail list.

What I am looking for is that when i scroll through the mail list it should
give me some events like load/unload or GotFocus/LostFocus.

Any sample code on these lines?


Given your inputs on item.Close() and Inspector.Close() events, I tried, but
they do not get triggered. More over I found Inspector.Close() is a method
and not a event.


Regards
 
K

Ken Slovak - [MVP - Outlook]

There are a number of Outlook methods that also have events of the same
name: Send, Close, Forward, Reply, etc. That doesn't mean the events don't
exist.

In those cases, especially with C#, you must use one of the special events
references such as the InspectorEvents_Event selection. For an Inspector
here's how I'd set up that event handler using C#:

((Outlook.InspectorEvents_Event)_insp).Close +=
new Outlook.InspectorEvents_CloseEventHandler(InspClose);

In that line "_insp" is a class level Inspector object and "InspClose" is
the handler procedure. "Outlook" is an alias established using this line at
the class level:

using Outlook=Microsoft.Office.Interop.Outlook;

When an item is opened it fires NewInspector() and the Inspector events will
then be available (assuming you handle them). The item events are also then
available for handling.

When an item is viewed in a folder view in the reading pane it does fire the
item.Read() event, but you need a handle to the item to be able to sink that
event. In that case you look to the Explorer, specifically the
ActiveExplorer() object. You handle the SelectionChange() event on the
Explorer and as the Selection collection changes you can set up to handle
item events for every item in the Selection collection.

You usually also handle the Explorer.BeforeFolderSwitch() event so you know
if the folder being switched to is one where you want to handle events.

One tip, Outlook collections, like many COM collections, start at index ==
1. So don't start iterating a collection like Selection at index 0, it's
invalid.

For sample code for the events we're talking about go to www.outlookcode.com
and search on those events. There's lots of sample code there for those and
other things in both C# and VB.NET.
 
J

JIGNESH

Fantastic. Thanks Ken... This information is quit helpful.
I believe "ActiveExplorer" will solve my missing links.

Regards
JIGNESH
 

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