formi
asked on
Outlook automation with Logon
Hi,
Delphi XE7, Outlook 2013 with 2 profiles
I have the following code:
1. if outlook is already executed I get an error (by CreateOleObject) "starting the server failed"
2. if outlook is not started outlook starts and displays a message to choose the profile (by CreateOleObject('Outlook.A pplication ') and all works fine, but I won't log on and use outlook invisible and automatic. How can I do that?
Thanks, Peter
Delphi XE7, Outlook 2013 with 2 profiles
I have the following code:
OutlookApp := CreateOleObject('Outlook.Application');
Mapi := OutlookApp.GetNameSpace('MAPI');
if MapiLogOn(0,PAnsiChar(AnsiString(Profile)),'',MAPI_NEW_SESSION,0,@hSession) = 0 then
begin
....
end;
I have 2 problems:1. if outlook is already executed I get an error (by CreateOleObject) "starting the server failed"
2. if outlook is not started outlook starts and displays a message to choose the profile (by CreateOleObject('Outlook.A
Thanks, Peter
1.
You should connect to existing one if exists:
Great examples was on (non existing anymore) page:
http://www.djpate.freeserv e.co.uk/Au toOutl.htm
...but found archive of page here...
2.
Check my answer to an similar question...
You should connect to existing one if exists:
try
OutlookApp := GetActiveOleObject('Outlook.Application');
except
OutlookApp := CreateOleObject('Outlook.Application');
end;
...
Great examples was on (non existing anymore) page:
http://www.djpate.freeserv
...but found archive of page here...
2.
Check my answer to an similar question...
ASKER
@John: I need help in Delphi-programming
@Sinisa: I have read that that's not valid for office-programs. There, if you call CreateOleObject and the program is already started it connects to the existing one. GetActiveOleObjects always throws an exception and it want be assigned.
@Sinisa: I have read that that's not valid for office-programs. There, if you call CreateOleObject and the program is already started it connects to the existing one. GetActiveOleObjects always throws an exception and it want be assigned.
Yes. I do not know Delphi. But, you need to use the Outlook command structure to open Outlook
Outlook /Profile <profilename>
And then you can only open one at a time.
Outlook /Profile <profilename>
And then you can only open one at a time.
Also, and so we are clear, your script cannot run if Outlook is Open. Outlook must be closed for the script to run. Why? Outlook cannot open unless it opens an account (outlook profile) and you cannot run another Outlook profile while one is running.
Most of what you are up against here is Outlook and not Delphi.
Most of what you are up against here is Outlook and not Delphi.
ASKER
John, have a look at what I wrote @Sinisa. If you create an new OleObject and Outllook already runs it doesn't create a second one but it connects to it.
Outlook will run but it will use the profile already loaded - just a second occurrence.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Found myself that it was a problem of Delphi edition. Second question is not answered.
1. Outlook already started: You can only have one active profile. So that explains point 1.
2. Outlook not started: You have to define the profile you want in the command line to start Outlook.
I do this (point 2) to run two different Outlook sessions on the same Desktop session. But only one can run at one time.