Outlook ItemSend Event: Get Total Editing Time of Email

B

Ben

Hi

We are writing a COM Addin to get the total editing time () of an email when
it is sent using Outlook.

Ideally we would like to do this using the SentItem Folder´s ItemAdd event
but initially we are trying this using the ItemSend event.

I cannot seem to do this, any help would be much appreciated.

Thanks
B
 
K

Ken Slovak - [MVP - Outlook]

Users can set items to not go to Sent Items, either on a one-off or global
basis. If you track the start using NewInspector and test for
Inspector.CurrentItem.Class = olMail you know when the item was opened.
Item.Send will tell you when it's sent.
 
B

Ben

Hi Ken

Thanks for your post:

I have this code currently but have two more questions:

Private Sub myOlInspectors_NewInspector(ByVal Inspector As
Outlook.Inspector)
If Not (Inspector.CurrentItem.Class = olMail) Then Exit Sub

End Sub

1/ VS says i must declare olMail

2/ Also how to I identify that the mailitem that has been created is the
same item when it is sent, because the user could open two mail items?

Thanks
B
 
K

Ken Slovak - [MVP - Outlook]

Well, one alternative would be something like this:

object Item = Inspector.CurrentItem;
if (Item is Ol.MailItem)

Another thing would be to fully qualify your reference for olMail:

OlObjectClass.olMail or even Microsoft.Office.Interop.Outlook.OlObjectClass

One thing you could do would be to get the item being sent in Item.Send and
calculate your time in that event handler. Another possibility would be to
just check for a user property you added with the start of editing time and
calculate the running edit time from that.

Of course if the user saves the item, not sends it, then re-opens it at some
other time and edits some more and then sends it you'd have to keep a
running total:

If (item has no user property for editing time)
add property
set start time
Else
already edited
add new property that indicates that a continued edit is taking place,
put current time in property

Then when sending (or in ItemAdd) use that logic to get the edit time from
second property if there and add to original added property time, if second
property not there then sent on original edit, get edit time from that.
 
R

rkozlin

Hey Ken,


I have a related question - sorry for the tangent, but I just cannot find an
answer to this anywhere...

How do you get a handle on the Item.Send event when using C# in VS2005?

From other posts I have been able to piece together that this might be
possible in VS2003 (although I have not attempted it), but in VS2005 you get
a cast exception.

The root of the issue is that the MailItem object in the
Microsoft.Office.Interop.Outlook assembly does not have an available Send
event because it seems to be hidden by the Send method. So this brings us to
MailItemClass, but the problem with that is I cannot figure out how to
instantiate the damn thing off of the currently open Inspector. The
following line of code fails:

MailItemClass oMailClass = (MailItemClass)((MailItem)oInspector.CurrentItem)

Here is the exception:

Unable to cast COM object of type 'System.__ComObject' to class type
'Microsoft.Office.Interop.Outlook.MailItemClass'. COM components that enter
the CLR and do not support IProvideClassInfo or that do not have any interop
assembly registered will be wrapped in the __ComObject type. Instances of
this type cannot be cast to any other class; however they can be cast to
interfaces as long as the underlying COM component supports QueryInterface
calls for the IID of the interface.


Any guidance please?


Thanks,

Rick
 

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