Opening Outlook Application

I am trying to open Outlook using DXL. I have been trying to use the "oleCreateAutoObject" function to open Outlook. I have successfully opened Excel, Word, and Visio using this method but not Outlook. Does anyone know why? Is there a work around? My code is basically the example in the DXL manual after the "oleCreateAutoOject" function.
Thanks.
HiLbiLy - Mon Jul 19 14:44:57 EDT 2010

Re: Opening Outlook Application
llandale - Tue Jul 20 17:06:06 EDT 2010

I know almost nothing about OLE, but I did manage to get a handle on an existing Outlook using

OleAutoObj oaoOutlook = oleGetAutoObject("Outlook.Application")

Looking at the code I see I try nothing if its not running and just send error to the user. Surely I would have TRIED oleCreateAutoObject, leading me to suspect I could not do it either.

Don't know if this a permamant fix, perhaps someone will comment, but perhaps you could force Outlook to run and THEN get a handle on it.

string  OutlookKeyName   = "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\OUTLOOK.exe"
string  OutlookValueName = ""    // Default
string  OutlookPath = getRegistry(OutlookKeyName, OutlookValueName)
print "Outlook path: [" OutlookPath "]\n"
system(OutlookPath)
sleep_(3000)            // 3 second wait
OleAutoObj oaoOutlook = oleGetAutoObject("Outlook.Application")


The 'system' - 'sleep_' combo is because I cannot make the win32SystemWait_ command work right.

 

 

  • Louie

 

 

Re: Opening Outlook Application
HiLbiLy - Wed Jul 21 07:13:34 EDT 2010

llandale - Tue Jul 20 17:06:06 EDT 2010

I know almost nothing about OLE, but I did manage to get a handle on an existing Outlook using

OleAutoObj oaoOutlook = oleGetAutoObject("Outlook.Application")

Looking at the code I see I try nothing if its not running and just send error to the user. Surely I would have TRIED oleCreateAutoObject, leading me to suspect I could not do it either.

Don't know if this a permamant fix, perhaps someone will comment, but perhaps you could force Outlook to run and THEN get a handle on it.

string  OutlookKeyName   = "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\OUTLOOK.exe"
string  OutlookValueName = ""    // Default
string  OutlookPath = getRegistry(OutlookKeyName, OutlookValueName)
print "Outlook path: [" OutlookPath "]\n"
system(OutlookPath)
sleep_(3000)            // 3 second wait
OleAutoObj oaoOutlook = oleGetAutoObject("Outlook.Application")


The 'system' - 'sleep_' combo is because I cannot make the win32SystemWait_ command work right.

 

 

  • Louie

 

 

Louie, I have been able to get a handle on Outlook using the 'get' function if Outlook is open, but I wanted outlook to open if it was closed. I had created a way force outlook open, similar to what you state above, but I was hoping for a cleaner solution. I just wanted to verify that I wasn't overlooking something obvious.
Thanks.

Re: Opening Outlook Application
Mathias Mamsch - Wed Jul 21 11:58:44 EDT 2010

HiLbiLy - Wed Jul 21 07:13:34 EDT 2010
Louie, I have been able to get a handle on Outlook using the 'get' function if Outlook is open, but I wanted outlook to open if it was closed. I had created a way force outlook open, similar to what you state above, but I was hoping for a cleaner solution. I just wanted to verify that I wasn't overlooking something obvious.
Thanks.

I guess the not so obvious thing is, that the outlook api works well without an explorer window (excel and word do not). You need to explicitly create an explorer tell Outlook to show an explorer window.
After googling a bit, I fumbled together the VBS code:
 

Set myOlApp = CreateObject("Outlook.Application")
Set myNms = myOlApp.GetNamespace("MAPI")
Set myExplorer = myOlApp.Explorers.Add(myNms.GetDefaultFolder(olFolderInbox), olFolderDisplayNormal)
myExplorer.Activate

 


which translates in DXL to something like this:

 

 

 

OleAutoObj oaoOutlook = oleCreateAutoObject("Outlook.Application")
OleAutoObj myExplorers
OleAutoObj myExplorer
OleAutoObj myNamespace
OleAutoObj myFolder
 
OleAutoArgs args = create() 
put(args, "MAPI")
print "5 " oleMethod (oaoOutlook, "GetNamespace", args, myNamespace)
 
clear args
 
// Get a handle to the inbox folder
put(args, 6) // olFolderInbox
print "4 " oleMethod (myNamespace, "GetDefaultFolder", args, myFolder)
 
// Create an explorer for the inbox
clear args
put(args, myFolder)
put(args, 0)   // olFolderDisplayNormal
 
 
// Get the Explorers collection
print "3 " oleGet (oaoOutlook, "Explorers", myExplorers)
print "2 " oleMethod (myExplorers, "Add", args, myExplorer)
print "1 " oleMethod(myExplorer, "Activate")



At least it seems to open Outlook, but not close it. To make it a clean solution you would need to check the "ActiveExplorer" property of the oaoOutlookApp and only create a new explorer if there is none yet and maybe perform cleanup. Regards, Mathias



 

 

 

 


Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS

 

 

Re: Opening Outlook Application
HiLbiLy - Thu Jul 22 06:18:54 EDT 2010

Mathias Mamsch - Wed Jul 21 11:58:44 EDT 2010

I guess the not so obvious thing is, that the outlook api works well without an explorer window (excel and word do not). You need to explicitly create an explorer tell Outlook to show an explorer window.
After googling a bit, I fumbled together the VBS code:
 

Set myOlApp = CreateObject("Outlook.Application")
Set myNms = myOlApp.GetNamespace("MAPI")
Set myExplorer = myOlApp.Explorers.Add(myNms.GetDefaultFolder(olFolderInbox), olFolderDisplayNormal)
myExplorer.Activate

 


which translates in DXL to something like this:

 

 

 

OleAutoObj oaoOutlook = oleCreateAutoObject("Outlook.Application")
OleAutoObj myExplorers
OleAutoObj myExplorer
OleAutoObj myNamespace
OleAutoObj myFolder
 
OleAutoArgs args = create() 
put(args, "MAPI")
print "5 " oleMethod (oaoOutlook, "GetNamespace", args, myNamespace)
 
clear args
 
// Get a handle to the inbox folder
put(args, 6) // olFolderInbox
print "4 " oleMethod (myNamespace, "GetDefaultFolder", args, myFolder)
 
// Create an explorer for the inbox
clear args
put(args, myFolder)
put(args, 0)   // olFolderDisplayNormal
 
 
// Get the Explorers collection
print "3 " oleGet (oaoOutlook, "Explorers", myExplorers)
print "2 " oleMethod (myExplorers, "Add", args, myExplorer)
print "1 " oleMethod(myExplorer, "Activate")



At least it seems to open Outlook, but not close it. To make it a clean solution you would need to check the "ActiveExplorer" property of the oaoOutlookApp and only create a new explorer if there is none yet and maybe perform cleanup. Regards, Mathias



 

 

 

 


Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS

 

 

Thanks!

Re: Opening Outlook Application
SystemAdmin - Thu Feb 28 17:43:01 EST 2013

Hello,

If outlook is not open how go you get a handle on the object before you call fEmailCreateOutlookMail am I overlooking something it seem I don't get a handle until it click on outlook.
 

//https://www.ibm.com/developerworks/forums/thread.jspa?messageID=14487162&#14487162
//https://www.ibm.com/developerworks/forums/thread.jspa?messageID=14488816&#14488816
//"c:\program files (x86)\microsoft office\office14\outlook.exe" /nopreview
pragma runLim, 0
 
const string    gl_OleOutlookApp        = "Outlook.Application"       // Windows recognizes this as a running Outlook
 
if (null oleGetAutoObject(gl_OleOutlookApp))
{
        string  OutlookKeyName   = "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\OUTLOOK.exe"
        string  OutlookValueName = ""    // Default
        string  OutlookPath      = getRegistry(OutlookKeyName, OutlookValueName)
        //print "Outlook path: [" OutlookPath "]\n"
        system(OutlookPath)
}
 
bool fOleOK( string CreateItem, To)
{
        bool ret = false
        if(null CreateItem) { ret = true }
        else{errorBox(To ": " CreateItem)}
        
        return (ret)
}
 
//******************************
bool    fEmailCreateOutlookMail(bool DoSend, string SendTo, SendCC, SendBCC, Subject, Body)
{     // Create the Email message which requires that Outlook.exe is running.
        // SendTo, SendCC, and SendBCC should be valid Email addresses separated by semi-colons;.
        // Send the Message when DoSend, otherwise just display it.
 
 
        bool    Result  = false
        OleAutoObj      oaoMessage      = null
        OleAutoObj      oaoOutlook      = oleGetAutoObject(gl_OleOutlookApp)
        if (null oaoOutlook)
        { 
           fOleOK("Outlook not running", "GetOutlook")      // Log Error
           return(false)
        }
        OleAutoArgs     autoArgs        = create()
        clear(autoArgs)
        put(autoArgs, 0)           // 0 is Outlook's symbolic constant for mail item
 
        if(fOleOK(oleMethod(oaoOutlook, "CreateItem", autoArgs, oaoMessage), "CreateItem")  and
                fOleOK(olePut(oaoMessage, "To",      SendTo),   "To")       and
                fOleOK(olePut(oaoMessage, "CC",      SendCC),   "CC")       and
                fOleOK(olePut(oaoMessage, "BCC",     SendBCC),  "BCC")      and
                fOleOK(olePut(oaoMessage, "Subject", Subject),  "Subject")  and
                fOleOK(olePut(oaoMessage, "Body",    Body),     "Body")
          )
        {            // Message created OK. Send or just Show it
           if (DoSend)
                Result = fOleOK(oleMethod(oaoMessage, "Send"), "Send")
           else Result = fOleOK(oleMethod(oaoMessage, "Display"), "Display")
        }
        else Result = false
        delete(autoArgs)
        return(Result)
}    // end fEmailCreateOutlookMail()
 
fEmailCreateOutlookMail(false,"SendTo@ABC.com",null,null,"Subject","Body")

 


-Jim

 

Re: Opening Outlook Application
SystemAdmin - Fri Mar 01 01:59:43 EST 2013

Mathias Mamsch - Wed Jul 21 11:58:44 EDT 2010

I guess the not so obvious thing is, that the outlook api works well without an explorer window (excel and word do not). You need to explicitly create an explorer tell Outlook to show an explorer window.
After googling a bit, I fumbled together the VBS code:
 

Set myOlApp = CreateObject("Outlook.Application")
Set myNms = myOlApp.GetNamespace("MAPI")
Set myExplorer = myOlApp.Explorers.Add(myNms.GetDefaultFolder(olFolderInbox), olFolderDisplayNormal)
myExplorer.Activate

 


which translates in DXL to something like this:

 

 

 

OleAutoObj oaoOutlook = oleCreateAutoObject("Outlook.Application")
OleAutoObj myExplorers
OleAutoObj myExplorer
OleAutoObj myNamespace
OleAutoObj myFolder
 
OleAutoArgs args = create() 
put(args, "MAPI")
print "5 " oleMethod (oaoOutlook, "GetNamespace", args, myNamespace)
 
clear args
 
// Get a handle to the inbox folder
put(args, 6) // olFolderInbox
print "4 " oleMethod (myNamespace, "GetDefaultFolder", args, myFolder)
 
// Create an explorer for the inbox
clear args
put(args, myFolder)
put(args, 0)   // olFolderDisplayNormal
 
 
// Get the Explorers collection
print "3 " oleGet (oaoOutlook, "Explorers", myExplorers)
print "2 " oleMethod (myExplorers, "Add", args, myExplorer)
print "1 " oleMethod(myExplorer, "Activate")



At least it seems to open Outlook, but not close it. To make it a clean solution you would need to check the "ActiveExplorer" property of the oaoOutlookApp and only create a new explorer if there is none yet and maybe perform cleanup. Regards, Mathias



 

 

 

 


Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS

 

 

Hi

> OleAutoObj oaoOutlook = oleCreateAutoObject("Outlook.Application")

This is standard-VBA. Create means "Start the program and get a handle" and Get means only "get a handle".
 

OleAutoObj vbaAppInit(string sApp) {
    OleAutoObj oleApp = oleGetAutoObject(sApp);
        if (oleApp == null) {
            oleApp = oleCreateAutoObject(sApp);
        }
        if (oleApp == null) {
            print "The user does not have a " sApp " installation");
        }
        return oleApp;
}
 
OleAutoObj objOutlook = vbaAppInit("Outlook.Application");

 


Best regards
Wolfgang

 

Re: Opening Outlook Application
llandale - Sat Mar 02 16:59:58 EST 2013

SystemAdmin - Thu Feb 28 17:43:01 EST 2013

Hello,

If outlook is not open how go you get a handle on the object before you call fEmailCreateOutlookMail am I overlooking something it seem I don't get a handle until it click on outlook.
 

//https://www.ibm.com/developerworks/forums/thread.jspa?messageID=14487162&#14487162
//https://www.ibm.com/developerworks/forums/thread.jspa?messageID=14488816&#14488816
//"c:\program files (x86)\microsoft office\office14\outlook.exe" /nopreview
pragma runLim, 0
 
const string    gl_OleOutlookApp        = "Outlook.Application"       // Windows recognizes this as a running Outlook
 
if (null oleGetAutoObject(gl_OleOutlookApp))
{
        string  OutlookKeyName   = "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\OUTLOOK.exe"
        string  OutlookValueName = ""    // Default
        string  OutlookPath      = getRegistry(OutlookKeyName, OutlookValueName)
        //print "Outlook path: [" OutlookPath "]\n"
        system(OutlookPath)
}
 
bool fOleOK( string CreateItem, To)
{
        bool ret = false
        if(null CreateItem) { ret = true }
        else{errorBox(To ": " CreateItem)}
        
        return (ret)
}
 
//******************************
bool    fEmailCreateOutlookMail(bool DoSend, string SendTo, SendCC, SendBCC, Subject, Body)
{     // Create the Email message which requires that Outlook.exe is running.
        // SendTo, SendCC, and SendBCC should be valid Email addresses separated by semi-colons;.
        // Send the Message when DoSend, otherwise just display it.
 
 
        bool    Result  = false
        OleAutoObj      oaoMessage      = null
        OleAutoObj      oaoOutlook      = oleGetAutoObject(gl_OleOutlookApp)
        if (null oaoOutlook)
        { 
           fOleOK("Outlook not running", "GetOutlook")      // Log Error
           return(false)
        }
        OleAutoArgs     autoArgs        = create()
        clear(autoArgs)
        put(autoArgs, 0)           // 0 is Outlook's symbolic constant for mail item
 
        if(fOleOK(oleMethod(oaoOutlook, "CreateItem", autoArgs, oaoMessage), "CreateItem")  and
                fOleOK(olePut(oaoMessage, "To",      SendTo),   "To")       and
                fOleOK(olePut(oaoMessage, "CC",      SendCC),   "CC")       and
                fOleOK(olePut(oaoMessage, "BCC",     SendBCC),  "BCC")      and
                fOleOK(olePut(oaoMessage, "Subject", Subject),  "Subject")  and
                fOleOK(olePut(oaoMessage, "Body",    Body),     "Body")
          )
        {            // Message created OK. Send or just Show it
           if (DoSend)
                Result = fOleOK(oleMethod(oaoMessage, "Send"), "Send")
           else Result = fOleOK(oleMethod(oaoMessage, "Display"), "Display")
        }
        else Result = false
        delete(autoArgs)
        return(Result)
}    // end fEmailCreateOutlookMail()
 
fEmailCreateOutlookMail(false,"SendTo@ABC.com",null,null,"Subject","Body")

 


-Jim

 

See Wolfgang's post just above. That was bit of an oversight on my part when I first wrote the code; being my first foray into "OLE". I'll update mine to look like that.

I did find it rather curious that if you start Outlook and then close it; "get" still works and you don't have to "create".

-Louie

Re: Opening Outlook Application
SystemAdmin - Mon Mar 04 02:26:18 EST 2013

llandale - Sat Mar 02 16:59:58 EST 2013
See Wolfgang's post just above. That was bit of an oversight on my part when I first wrote the code; being my first foray into "OLE". I'll update mine to look like that.

I did find it rather curious that if you start Outlook and then close it; "get" still works and you don't have to "create".

-Louie

Hi

An office application does not really close if you close it. Just in this time, I've closed my outlook and close really did work. May be there is a communication with your exchange or something else is runnig in the background only the dialog disappears.

Best regards
Wolfgang

Re: Opening Outlook Application
llandale - Mon Mar 04 12:59:58 EST 2013

SystemAdmin - Mon Mar 04 02:26:18 EST 2013
Hi

An office application does not really close if you close it. Just in this time, I've closed my outlook and close really did work. May be there is a communication with your exchange or something else is runnig in the background only the dialog disappears.

Best regards
Wolfgang

I see this 5-year-old comment I left for myself. I wish I could understand it!
  • fOutlook_StartProcess (oleCreateAutoObject) Bug: seems to start outlook for the duration of the script, (according to itself and looking for 'OUTLOOK.EXE' in the Task Manager) but fOutlook_IsRunning (oleGetAutoObject) doesn't recognize it.
  • Not sure what to think about this; perhaps there is more than one 'outlook.application' in the Registry.
I think it means, at least then, that attempting to START outlook wouldn't help

Re: Opening Outlook Application
SystemAdmin - Tue Mar 05 02:18:58 EST 2013

llandale - Mon Mar 04 12:59:58 EST 2013
I see this 5-year-old comment I left for myself. I wish I could understand it!

  • fOutlook_StartProcess (oleCreateAutoObject) Bug: seems to start outlook for the duration of the script, (according to itself and looking for 'OUTLOOK.EXE' in the Task Manager) but fOutlook_IsRunning (oleGetAutoObject) doesn't recognize it.
  • Not sure what to think about this; perhaps there is more than one 'outlook.application' in the Registry.
I think it means, at least then, that attempting to START outlook wouldn't help

> •fOutlook_StartProcess (oleCreateAutoObject) Bug: seems to start outlook for the duration of the script, (according to itself and looking for 'OUTLOOK.EXE' in the Task Manager) but fOutlook_IsRunning (oleGetAutoObject) doesn't recognize it.

Actually I've practial experience by using Word, Excel and Access but not in Outlook.

In those programs you actually can start more than one instances. I.E. if the user has an opened word session and you wanted to perform some "internal calculations" it is better to start an additionaly instance. In Office this makes no sense. You can test this by trying to start word several times and checking the result in the task manager. This works. If you try to start more than one outlook, this does not work. So outlook works different and you allways have 0 or 1 running programs.

You cannot terminate an applciation by releasing it's handle. The standard rule to terminate an application is oleAplicationObject.Quit and not oleCloseAutoObject.

But you might be right. It is possible that outlook is something different in both cases.

Re: Opening Outlook Application
Miha87 - Thu Dec 19 08:50:13 EST 2013

Mathias Mamsch - Wed Jul 21 11:58:44 EDT 2010

I guess the not so obvious thing is, that the outlook api works well without an explorer window (excel and word do not). You need to explicitly create an explorer tell Outlook to show an explorer window.
After googling a bit, I fumbled together the VBS code:
 

Set myOlApp = CreateObject("Outlook.Application")
Set myNms = myOlApp.GetNamespace("MAPI")
Set myExplorer = myOlApp.Explorers.Add(myNms.GetDefaultFolder(olFolderInbox), olFolderDisplayNormal)
myExplorer.Activate

 


which translates in DXL to something like this:

 

 

 

OleAutoObj oaoOutlook = oleCreateAutoObject("Outlook.Application")
OleAutoObj myExplorers
OleAutoObj myExplorer
OleAutoObj myNamespace
OleAutoObj myFolder
 
OleAutoArgs args = create() 
put(args, "MAPI")
print "5 " oleMethod (oaoOutlook, "GetNamespace", args, myNamespace)
 
clear args
 
// Get a handle to the inbox folder
put(args, 6) // olFolderInbox
print "4 " oleMethod (myNamespace, "GetDefaultFolder", args, myFolder)
 
// Create an explorer for the inbox
clear args
put(args, myFolder)
put(args, 0)   // olFolderDisplayNormal
 
 
// Get the Explorers collection
print "3 " oleGet (oaoOutlook, "Explorers", myExplorers)
print "2 " oleMethod (myExplorers, "Add", args, myExplorer)
print "1 " oleMethod(myExplorer, "Activate")



At least it seems to open Outlook, but not close it. To make it a clean solution you would need to check the "ActiveExplorer" property of the oaoOutlookApp and only create a new explorer if there is none yet and maybe perform cleanup. Regards, Mathias



 

 

 

 


Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS

 

 

Hi Mathias,

That's exactly what I need, but  how do I open an email with a certain subject.

I do not really understand.

regards Micha