Ask a Question

sending mail when outlook client closed

NisHera
Valued Contributor

sending mail when outlook client closed

I was trying send test result using outlook using flowing functions

function InitOutlook(){
  try{
    try{
      MsOutlook = Sys.OleObject("Outlook.Application");    }
    catch(exception){
      MsOutlook = Sys.OleObject("Outlook.Application.11");   } 
    NS = MsOutlook.GetNamespace("MAPI");
    //ContacFldr = NS.Folders("Personal Folders").Folders("Contacts");
    ContacFldr = NS.GetDefaultFolder(olFolderContacts);
  } 
  catch(exception){
    Log.Warning("Unable to initializa MS outlook ","generated from InitOutlook function"+exception, pmHigher);
    return false  }
  return true ;   
} 

and

 

function SendReport(FirstName,LastName,fileAttach){
  var ObjItem, MI, i, CRLF; 
  
  CRLF = "\n";
  
  ObjItem = GetContactByName(FirstName,LastName );
  if (ObjItem == null){Log.Error("User "+FirstName+"  "+LastName+"  Not found in the address book") }
  
  MI = MsOutlook.CreateItem(olMailItem);
  
  MI.Subject = "Test Results"
  
  MI.Body = " Hello..." + ObjItem.FirstName+CRLF+
            " How are you fine thank you ";
            
  MI.To = ObjItem.Email1Address;
  Log.Message(ObjItem.Email1Address);
  
  MI.Attachments.Add(fileAttach,olByValue,MI.Body.length);
  
  MI.Display();
  Delay(5000);
  
  MI.Send();
  
} 

when I closed outlook application both working I could see new message open up with correct attachment and closed.

But never mail was sent. it stuck at out box, only will be sent when out look opens up.

 

If I keep outlook open it there would be error from first function " InitOutlook() " error message was  "generated from InitOutlook functionError: Invalid class string: cannot obtain ClassID."

 

any idea?

 

1 REPLY 1
NisHera
Valued Contributor

never mind....it's easy to use testcomplete function "SendMail(....)"

it will directly connect to mail server so I don't have to worry about outlook client

cancel
Showing results for 
Search instead for 
Did you mean: