I have the following code in my test Delphi 2006 BDS application:
procedure TForm1.Button1Click(Sender: TObject);
const
olMailItem = 0;
var
Outlook: OleVariant;
vMailItem: variant;
begin
Outlook := CreateOleObject('Outlook.Application');
vMailItem := Outlook.CreateItem(olMailItem);
try
vMailItem.Recipients.add('anemailaddress@gmail.com');
vMailItem.Display(True); -- outlook mail message is displayed modally
except
end;
VarClear(Outlook);
end;
I need to be able to detect whether the user sent the email from within the outlook screen. I tried the following code:
if vMailItem.Sent then
...
But received the error message 'The item has been moved or deleted'. I presume this is because the mail item has moved to the sent items folder. What is the best way to detect if the user sent the email? Also, if the user did send the email then I would also need to be able to view the email body.
Thanks in advance.
It would seem you have to use the
Send Event
of the mail item. This would be a lot easier if you were using early binding, put one of the 'outlook[*].pas' files in the '..\OCX\Servers' folder of RAD studio in the 'uses' clause, then:With late binding, you'd have to do some of the work which the imported wrapper does. The simplest example could be something like this:
I came up with this solution using VBA that addresses the first part of your question. It basically relies on error handling to determine if the email WAS sent.