MailItem read Event

Add-in Express™ Support Service
That's what is more important than anything else

MailItem read Event
Getting the read event 
Julian Pointer


Guest


How do I get to the read event of a mail item, when a user opens an email i need to save the email details, this includes reading the email in the preview window. I do it in VB by the selectionchange of the ActiveExplorer and I then Set oMailItem = m_objExpl.Selection.Item(1) if this fails then its not a mailitem, otherwise I have a mail item and I then use the read event.
Posted 05 May, 2005 01:35:32 Top
Dmitry Kostochko


Add-in Express team


Posts: 2875
Joined: 2004-04-05
Hi Julian,

I hope the code below will help you. In general it is a little bit similar to the VB code and I think all will be clear for you.


procedure TAddInModule.adxCOMAddInModuleOLExplorerSelectionChange(Sender: TObject);
var
  MItem: _MailItem;
begin
  if OutlookApp.ActiveExplorer.Selection.Count 
>
 0 then
    OutlookApp.ActiveExplorer.Selection.Item(1).QueryInterface(IID__MailItem, MItem);
  if Assigned(MItem) then
    try
      FMail := TMailItem.Create(nil);
      FMail.ConnectTo(MItem);
      FMail.OnOpen := DoOpen;
      FMail.OnRead := DoRead;
      //...
      //...
    finally
      MItem := nil;
    end;
end;


Posted 05 May, 2005 10:29:52 Top
Julian Pointer


Guest


Hi
I couldn't get this code to work? I just declared the procedure as

TAddInModule = class(TadxCOMAddInModule)
adxOlInspectorCommandBar1: TadxOlInspectorCommandBar;
procedure adxCOMAddInModuleAddInInitialize(Sender: TObject);
procedure adxCOMAddInModuleAddInFinalize(Sender: TObject);
procedure adxCOMAddInModuleOLExplorerSelectionChange(Sender:TObject);

I did however use the "How to handle Outlook's SelectionChange event" and I have it almost working, One problem is I am getting the read event when I click on a new email in the Inbox with the preview screen off. I need to get the read event when, then open the email by double clicking on it or have the preview pane on and click on the email in the inbox. Any ideas how I can do this?

Posted 05 May, 2005 19:04:12 Top
Julian Pointer


Guest


I have it working now here is the code I used

IInsp := OutlookApp.ActiveInspector;
VIntf := NULL;

try
if Assigned(IInsp) then
VIntf := IInsp.CurrentItem
else
begin
VIntf := OutlookApp.ActiveExplorer.Selection;
if VIntf.Count > 0 then
VIntf := VIntf.Item(1)
else
VIntf := NULL;
end;

if not VarIsNULL(VIntf) then
if VIntf.Class = olMail then
begin

if Assigned(FMail) then FMail.Free;
OutlookApp.ActiveExplorer.Selection.Item(1).QueryInterface(IID__MailItem, MItem);
if Assigned(MItem) then
try
FMail := TMailItem.Create(nil);
FMail.ConnectTo(MItem);
// FMail.OnOpen := DoOpen;
FMail.OnRead := DoEmailRead;
finally
MItem := nil;
end;
end;
//MyActionOnSelectionChange(VIntf)

finally

VIntf := UnAssigned;
IInsp := nil;

end;
Posted 05 May, 2005 21:04:32 Top
Dmitry Kostochko


Add-in Express team


Posts: 2875
Joined: 2004-04-05
Hi Julian,

You are going the right way.

Posted 06 May, 2005 07:08:14 Top