Forum Discussion

eykxas's avatar
eykxas
Frequent Contributor
7 years ago

Problem with Outlook 2016 and TC12

Hi,

 

I have a problem with Outlook 2016. I want to get the Ole Object of Outlook with this method :

 

 

language javascript

var msOutlook = Sys.OleObject("Outlook.Application");

 

But Testcomplete send me an error message when outlook is running : Failed to run server, CLSID {0006F03A-0000-0000-C000-000000000046}.

 

If outlook is not running, then the code works fine, but outlook don't receive message, until it is open manually.

 

In TC10, I get the Ole Object no matter the state of outlook (running or not).

 

Have you a solution ?

12 Replies

  • eykxas's avatar
    eykxas
    Frequent Contributor

    No. But I've found a workaround with this code :

     

    function outlook_checkTC12(myInbox, folder, messageBody, subject){
    	var inbox, i;
    
    	var msOutlook = Sys.OleObject("Outlook.Application");
    
    	var mapi = msOutlook.GetNamespace("MAPI");
    	mapi.Logon("Outlook","password",false,true);
    	mapi.SendAndReceive(false);
    	Delay(10000);
    	var found = false;
    
    
    	if(myInbox==undefined) myInbox = get_inbox_outlook();
    	if(folder==undefined) folder = "Boîte de réception";
    
    	var inbox = mapi.Folders(myInbox).Folders(folder);
    	Log.Message(inbox.Items.Count + " e-mails");
    
    	for (i = 1; i <= inbox.Items.Count; i++)
    	{
    		toolEmail = inbox.Items.Item(i);
    		body = toolEmail.Body;
    		subject = toolEmail.Subject;
    
    		if (body.indexOf(messageBody) != -1 && subject.indexOf(subject) != -1)
    		{
    			Log.Message(toolEmail.Body + "And " + toolEmail.Subject);
    			Log.Message("The body and subject of the mail are verified");
    
    			Log.Message("Number of attachments: " + toolEmail.Attachments.Count);
    
    			//Attachments
    			for(j = 1;j<=toolEmail.Attachments.Count;j++){
    				Log.Message("Name of attachments"+j+" : " + toolEmail.Attachments(j).FileName);
    			}
    			//toolEmail.Delete();
    			found=true;
    			break;
    		} 
    		else 
    		{
    			continue;
    		}
    	}
    
    	if(!found){
    		Log.Error("The body and subject of the mail are not found");
    	}
    
    	msOutlook.Quit();
    }
  • sanjay0288's avatar
    sanjay0288
    Frequent Contributor

    This is because  Outlook can only run one session at a time. The better approach would be to test first for an existing Outlook process running and hook into it if it is running ; If the process is not running then create an Outlook session. Hope this might help.

    • eykxas's avatar
      eykxas
      Frequent Contributor

      Outlook MUST be running. (in order to receive mail in real time).

       

      Why I don't have this problem on TC10 ? Or maybe is the version of Outlook (2016 for the computer with TC12 and 2013 for TC10 ).

  • bertjefred's avatar
    bertjefred
    New Contributor

    Hi,

     

    I am having the same problem. I think it has to do with the Outlook version. It has been failing on me since moving to Windows 10 and Outlook 2016.

     

    Eykxas, did you have Outlook 2016 working at one time with TC10?

     

    Thank you.

     

    Kind regards

  • bertjefred's avatar
    bertjefred
    New Contributor

    Hi Eykxas,

     

    Thanks for the update!

    This totally works for me again now.

     

    Thanks a lot and a great weekend!

     

     

  • kevin_kapell's avatar
    kevin_kapell
    Frequent Contributor

    I have the same problem but the code work around does not work for me. The error occurson the line:

    var msOutlook = Sys.OleObject("Outlook.Application");

    • kevin_kapell's avatar
      kevin_kapell
      Frequent Contributor

      Additionally this only errors at this point if Outlook is already open. So can i check to see if it is already open and skip this line and continue? If so what do I check for?

      • bertjefred's avatar
        bertjefred
        New Contributor

        Yeah this is true.

         

        Before Outlok 2016 I could keep outlook open. Now it needs to be closed when running the test. For me this is not an issue. But I could see situations where this might be a problem in a certian scenario. So no sollution for that one yet.

  • eykxas's avatar
    eykxas
    Frequent Contributor

    With TC12 and Outlook 2016, TC12 can't access to Outlook if it's open. So I don't have a solution to keep outlook opened.

  • eykxas's avatar
    eykxas
    Frequent Contributor

    Obviously, with Outlook 2016, there cannot be more than one instance of Outlook. Maybe there is an option in the windows registry to retrieve the old behavior.

  • kevin_kapell's avatar
    kevin_kapell
    Frequent Contributor

    The solution I came up with is to look to see if outlook is running and if it is close it before making the connection. So far this seems to work.

     

        var OutLookProcess = Sys.WaitProcess("outlook",2000);
        if(OutLookProcess.Exists)
        {
          OutLookProcess.Close();
          aqUtils.Delay(2000);//Give time to close Outlook
        }
        var OutlookApplication = Sys.OleObject("Outlook.Application");