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. |
|
Dmitry Kostochko
Add-in Express team
Posts: 2880
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;
|
|
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?
|
|
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; |
|
Dmitry Kostochko
Add-in Express team
Posts: 2880
Joined: 2004-04-05
|
Hi Julian,
You are going the right way.
|
|