Capturing Outlook Forms Events

Status
Not open for further replies.
D

Duke2

Hi,

I'm new to Outlook forms programing, so this quesiotn may sound silly to you

guys. Please bear with me, if so.

I'm trying to retrieve the message ID when a user clicks on a message on

Outlook 2007 and run a script (a macro?) and thereby do some checks and if

the check qualifies the message for a certain condition replace the mesage

with a standard message that's stored locally as an .msg file.

I know how to call a macro but don't know how to link a macro to an event.

Also I don't know how to parse an msg file into IPM.Note form.

Could you help me by giving me some tips, pointing to some reference

matirals online and/or offline (books). I know these are very basic

operations in Outlook programming, but I'm clueless.

Thanks

Duke
 
S

Sue Mosher [MVP]

Are you asking what event fires when the user clicks on an item in a folder

window? That has nothing to do with Outlook custom forms. The relevant event

is Explorer.SelectionChange event.

What do you mean by "message ID"? By "replace the message," do you mean

replace the entire Outlook message item? Or replace the message body?

To bring an .msg file into Outlook, use the Namespace.OpenSharedItem method.

The book and web site mentioned in my signature supplement the basic

information available in VBA Help.

Sue Mosher

"Duke2" <Duke2> wrote in message

news:C0DDC369-A04A-4701-AE6A-2E73C50AD85B@microsoft.com...
> Hi,

> I'm new to Outlook forms programing, so this quesiotn may sound silly to
> you
> guys. Please bear with me, if so.

> I'm trying to retrieve the message ID when a user clicks on a message on
> Outlook 2007 and run a script (a macro?) and thereby do some checks and if
> the check qualifies the message for a certain condition replace the mesage
> with a standard message that's stored locally as an .msg file.

> I know how to call a macro but don't know how to link a macro to an event.
> Also I don't know how to parse an msg file into IPM.Note form.

> Could you help me by giving me some tips, pointing to some reference
> matirals online and/or offline (books). I know these are very basic
> operations in Outlook programming, but I'm clueless.

> Thanks
> > Duke
 
D

Duke2

Hi Sue,

Thanks for the quick response. I just bought your book "Outlook 2007

Programming" and just started learning Outlook programming.

I'm asking what event fires when the user clicks on an Outlook item, mainly

what events fire when user selects a message by clicking on an item on

Outlook main window. I didnt mean to say what events get fired on Windows

folder level.

I want to capture the unique ID of the message available in the header

called message_ID and then run a query against this message and see if it

qualifies for my special handling. If it does then I want to replace the

entire message with a stathc message that's stored locally in an msg file.

Thanks

Duke
 
S

Sue Mosher [MVP]

As I said, Explorer.SelectionChange is the event that fires when the user

clicks on an item in the main Outlook window.

To access the message header, you would use the PropertyAccessor object;

there's an example at

http://msdn.microsoft.com/en-us/lib...2007whatsnewdeveloperspart2__propertyaccessor.

It's VB.NET, but the basic approach would be similar in VBA, if that's what

you're writing code for.

What does "run a query against this message" mean in your scenario?

Sue Mosher

"Duke2" <Duke2> wrote in message

news:74EF8435-74FA-4596-A68A-34BB48B5C386@microsoft.com...
> Hi Sue,

> Thanks for the quick response. I just bought your book "Outlook 2007
> Programming" and just started learning Outlook programming.

> I'm asking what event fires when the user clicks on an Outlook item,
> mainly
> what events fire when user selects a message by clicking on an item on
> Outlook main window. I didnt mean to say what events get fired on Windows
> folder level.

> I want to capture the unique ID of the message available in the header
> called message_ID and then run a query against this message and see if it
> qualifies for my special handling. If it does then I want to replace the
> entire message with a stathc message that's stored locally in an msg file.

> Thanks
> > Duke
>
 
D

Duke2

Hi Sue,

By runnig a query I meant, using the email's message ID, I'd run a DB query

against the database stored in the same network and then based on the

results, I'll decide to show the original contents or show a static message

from an msg file (stored locally). I have a back end process running (on

Exchange Server) that sniffs through all email contents and if any of them

have some keyowrds, I want them not be show to the user and instead show a

standard message.

Thank you for directing me to the VB.NET sample. I'll attempt to rewrite it

in VBA. However I have a question, if I want to do this in VB.NEt then I have

to develop an Outlook add-in using VSTO I assume. Please tell me if my

assumption is right. I prefer to write code in C# (or VB.NET) and VBA is my

second choice.

If I can access the message header through PropertyAccessor object, where

should I run the script to access it? This is the most confusing part to me.

As I said before I can write some macros, but don't know how to call them

and/or link them to events.

Thanks

Duke
 
S

Sue Mosher [MVP]

As I said in my earlier response, Explorer.SelectionChange is the event that

fits your scenario. Any good VSTO add-in sample for Outlook should show you

how to work with various event handlers in C#.

I'm not sure your complete scenario is workable, though, unless you plan to

completely replace the original message as it arrives. There's no separate

functionality for controlling what's displayed in the reading pane. Also,

users could turn on AutoPreview, which would show them some of the message

contents even before they click on a particular message. Since you already

have a server process running, maybe it should be doing the message

replacement operation.

Sue Mosher

"Duke2" <Duke2> wrote in message

news:797FBA96-F112-4DC7-96CA-FC6519468A5D@microsoft.com...
> Hi Sue,

> By runnig a query I meant, using the email's message ID, I'd run a DB
> query
> against the database stored in the same network and then based on the
> results, I'll decide to show the original contents or show a static
> message
> from an msg file (stored locally). I have a back end process running (on
> Exchange Server) that sniffs through all email contents and if any of them
> have some keyowrds, I want them not be show to the user and instead show a
> standard message.

> Thank you for directing me to the VB.NET sample. I'll attempt to rewrite
> it
> in VBA. However I have a question, if I want to do this in VB.NEt then I
> have
> to develop an Outlook add-in using VSTO I assume. Please tell me if my
> assumption is right. I prefer to write code in C# (or VB.NET) and VBA is
> my
> second choice.

> If I can access the message header through PropertyAccessor object, where
> should I run the script to access it? This is the most confusing part to
> me.
> As I said before I can write some macros, but don't know how to call them
> and/or link them to events.

> Thanks
> Duke
 
D

Duke2

Thank you for the reply. In my case though I can not use VSTO but should

stick to macros as I'm not allowed to install anything on client's machines.

I hope this is something that can be done in Outlook 2007.

Yes, my intention is to replace the whole message and not just few fields

like body, subject. However if I do this in the back-end, the replacement

will be permanent I assume. That's also something that's not allowed. I have

to preserve the original message and at the same time display a different

message to the user. If I can replace the complete message as it arrives, my

goal is achieved.
 
S

Sue Mosher [MVP]

Before you go down that road, you should be aware that there's no simple way

to distribute VBA code to other users; see

http://www.outlookcode.com/article.aspx?id=28 Also, users can delete VBA

code easily. How are you planning to avoid that?


> I have
> to preserve the original message and at the same time display a different
> message to the user. If I can replace the complete message as it arrives,
> my
> goal is achieved.


And do what with the original message? Also, if this is an Exchange

environment, wouldn't the user be able to see the full message with OWA?

Sue Mosher

"Duke2" <Duke2> wrote in message

news:5FCB489B-9A54-4A43-873A-33B9D3456063@microsoft.com...
> Thank you for the reply. In my case though I can not use VSTO but should
> stick to macros as I'm not allowed to install anything on client's
> machines.
> I hope this is something that can be done in Outlook 2007.

> Yes, my intention is to replace the whole message and not just few fields
> like body, subject. However if I do this in the back-end, the replacement
> will be permanent I assume. That's also something that's not allowed. I
> have
> to preserve the original message and at the same time display a different
> message to the user. If I can replace the complete message as it arrives,
> my
> goal is achieved.
 
D

Duke2

I thought by publishing into Organizational Forms Library, I can easily

distribute these macros to the users. But after looking at your post, I'm bit

worried.

my intention is not to show the message's original contents if it qualifies

my criteria (as I described before). I've also modified OWA premium pages to

do the same thing. OWA part is prety much complete, but it appears that

without installing anything on client's machine, I wont be able to do the

same thing with Outlook.

If we forget the distribution difficulty for a minute and think this only

needs to work on a single Outlook instance, how can I capture the events and

call a macro? Can you show me an example of this?

Thanks

Duke
 
S

Sue Mosher [MVP]

Forms published to the Organizational Forms library run VBScript code, not

VBA code, and would not provide a solution for your scenario.

These articles on Outlook events include VBA code samples and are also

available in VBA Help on your machine:

http://msdn.microsoft.com/en-us/library/bb147654.aspx -

Explorer.SelectionChange

http://msdn.microsoft.com/en-us/library/bb147644.aspx -

Inspectors.NewInspector

Still looking for an answer to my question about what you plan to do with

the original message's content if you replace all the fields with data from

some other source.

Sue Mosher

"Duke2" <Duke2> wrote in message

news:526832FB-2545-42AD-A465-9362D948A631@microsoft.com...
> I thought by publishing into Organizational Forms Library, I can easily
> distribute these macros to the users. But after looking at your post, I'm
> bit
> worried.

> my intention is not to show the message's original contents if it
> qualifies
> my criteria (as I described before). I've also modified OWA premium pages
> to
> do the same thing. OWA part is prety much complete, but it appears that
> without installing anything on client's machine, I wont be able to do the
> same thing with Outlook.

> If we forget the distribution difficulty for a minute and think this only
> needs to work on a single Outlook instance, how can I capture the events
> and
> call a macro? Can you show me an example of this?

> Thanks
> Duke

>
 
D

Duke2

I'm sorry for not being clear on what am I going to do to the original

message. I'm simply not going to show it the recipient, but then forward a

copy (through a back end process run on Exchagne Server) to an auditor and

preserve it as evidence. In case the auditor gives the approval I'll remove

the blocked status on the message and afterwards user will be able to see the

original contents.

Thanks for the links, I'll check them out now.

Duke

BTW: Pete McClean told me to say hi to you.
 
S

Sue Mosher [MVP]

This sounds like a scenario that should be implemented totally at the server

level, with no client-side functionality involved, much as some spam filters

operate.

Sue Mosher

"Duke2" <Duke2> wrote in message

news:4A677945-AF79-4A96-BD69-83C92CABD86C@microsoft.com...
> I'm sorry for not being clear on what am I going to do to the original
> message. I'm simply not going to show it the recipient, but then forward a
> copy (through a back end process run on Exchagne Server) to an auditor
> and
> preserve it as evidence. In case the auditor gives the approval I'll
> remove
> the blocked status on the message and afterwards user will be able to see
> the
> original contents.

> Thanks for the links, I'll check them out now.
> Duke

> BTW: Pete McClean told me to say hi to you.
 
D

Duke2

Hi Sue,

Thank you very much for the advise. I'm now convinced that doing this

operation at client side is not possible.

However to do this at server side, I need to capture message selection event

and then run my check on the server. Do you think Exchange will allow me to

capture message selection events? I know this is something that's not

possible with EWS as it's essentially a request-based set of operations.
 
S

Sue Mosher [MVP]

Message selection, being a client function, doesn't fire an event on the

server. But if you modify the contents of the all the messages as they

arrive it, you don't need selection.

Sue Mosher

"Duke2" <Duke2> wrote in message

news:3C709176-5371-42A8-B647-F39B37EE0FBB@microsoft.com...
> Hi Sue,

> Thank you very much for the advise. I'm now convinced that doing this
> operation at client side is not possible.

> However to do this at server side, I need to capture message selection
> event
> and then run my check on the server. Do you think Exchange will allow me
> to
> capture message selection events? I know this is something that's not
> possible with EWS as it's essentially a request-based set of operations.
 
D

Duke2

Hi Sue,

I'm sorry for making things confusing. Let me explain my requirement in a

differnet (hopefully) simpler way.

When a I select a message by clicking on it on Outlook, I want to capture

that event and inside that event I want to retrieve its message ID, and

instead of retrieving the message X (which it should retrieve), I want to

retrieve message Y from the same mailbox. Is this something possible to do in

Outlook forms?

Thanks

Duke
 
S

Sue Mosher [MVP]

You mean "display," not "retrieve" for the messages, right? And you also

have the requirement, I presume, to prevent the user from seeing the

original item's content. If so, the only way to accomplish those goals is

for the original content to have been replaced *before* the user can do

anything with the item, and that's not something that can be done with an

Outlook form alone.

Sue Mosher

"Duke2" <Duke2> wrote in message

news:16759675-411D-40A3-ACA6-5126BEA89C6B@microsoft.com...
> Hi Sue,

> I'm sorry for making things confusing. Let me explain my requirement in a
> differnet (hopefully) simpler way.

> When a I select a message by clicking on it on Outlook, I want to capture
> that event and inside that event I want to retrieve its message ID, and
> instead of retrieving the message X (which it should retrieve), I want to
> retrieve message Y from the same mailbox. Is this something possible to do
> in
> Outlook forms?

> Thanks
> Duke
 
D

Duke2

Hi Sue,

No I mean "retrieve" not just "display". Can I change Outlook to retrieve a

different message instead of the message it's supposed to retrieve from

server?

Thanks

Duke
 
S

Sue Mosher [MVP]

In a programming context, "retrieve" generally means to return values from

some source. You can return whatever values you want from whatever source

you want, but if you want to block the message -- as your previous posts

indicated -- then I can only assume that you're talking about what is

displayed in the UI. So, that's "display," not "retrieve."

Or do you have some other scenario in mind?

Sue Mosher

"Duke2" <Duke2> wrote in message

news:144FAE33-14A8-405B-A5CC-317341AF26BA@microsoft.com...
> Hi Sue,

> No I mean "retrieve" not just "display". Can I change Outlook to retrieve
> a
> different message instead of the message it's supposed to retrieve from
> server?

> Thanks
> Duke

>
 
D

Duke2

Yes in that context it's "display". I only want to display a different

message without replacing the original message in the server. So later on

when I want to, I can display the original message.

In perview however, I dont mind showing the original message.

Thanks

Duke
 
S

Sue Mosher [MVP]

Well, I can't say that makes any sense to me. I mean, what's the point of

showing the user one thing in the reading pane and another thing in the

Inspector window. That sounds like a recipe for confusion. It's certainly

not a scenario that would fit any definition of blocking that I've ever

encountered.

But if you want to do it, just use a custom form for those items that runs

whatever code you want in the Item_Open event handler. Or, even simpler,

design the custom form so that the only visible page has a text box on it

with whatever it is you want the user to see, rather than the message body.

All subject, of course, to the warning I gave earlier about potential

problems with attachments if any of these items are forwarded.

Sue Mosher

"Duke2" <Duke2> wrote in message

news:3052217B-0B0B-41CA-8972-F9C16ED2E5A7@microsoft.com...
> Yes in that context it's "display". I only want to display a different
> message without replacing the original message in the server. So later on
> when I want to, I can display the original message.

> In perview however, I dont mind showing the original message.

> Thanks
> Duke

>
 
Status
Not open for further replies.
Top