Ask a Question

how to config mailclient in test complete or how to send test result to mail via test complete

sanjayram
Occasional Contributor

how to config mailclient in test complete or how to send test result to mail via test complete

how to config mailclient in test complete or how to send test result to mail via test complete

 

Hi,  

      I'm using test complete and I want to send my log result for every single case after the test run completed even if it passed or failed , How can I config to make that happen?

 

9 REPLIES 9
rraghvani
Champion Level 3

sanjayram
Occasional Contributor

 Hi rraghavi,

 

need step-by-step guidance to perform the operation.

rraghvani
Champion Level 3

The first step is to read what I've provided; second step, is to try and understand it; third step, is to try it; fourth step, any issues then let us know.

 

I won't provide step by step guidance, as everything is mentioned in the TestComplete documentation.

 

 

Marsha_R
Champion Level 3

@sanjayram If you have questions after you've tried it, post your code and the results here and then we can try to help you.

sanjayram
Occasional Contributor

In this script MAPI has failed

 

Show us your script please. We can't see where it has gone wrong without that.
sanjayram
Occasional Contributor

//This example demonstrates how you can work with Microsoft Outlook from 
    scripts. It will send messages long with attached script code to John Smith,
    John Smith Corp., at JohnSmith@JohnSmithCorp.com.   

 

    Run the Outlook_Test procedure.

 

    Requirements:
       Microsoft Outlook must be installed on your computer.

 

    NOTE: This example adds a new contact (John Smith, John Smith Corp.) 
          to your address book. Don't forget to remove it later.  */

 

 

// MS Outlook constants
var
  olMailItem    = 0;
  olByValue     = 1;
  olContactItem = 2;

 

function Outlook_Test()
{
  var outlook = CreateOutlook()

 

  if (GetContactByName(outlook, "sanjayram", "raja", "optisolbusinesssolution") == null)
    AddContact(outlook, "sanjayram", "xxxx", "xxxxx", "sanjayram.r@xxxxx.com");

 

  SendReport(outlook, "sanjayram", "xxxx", "xxxxxxx", 
               Project.Path + "\\" + "Script\\Outlook_JS.sj");
}

 

// Initializes MS Outlook
//function CreateOutlook()
//{
  //try
  //{
    //return Sys.ActiveXObject("Outlook.Application");
   //}
  //catch (exception)
  //{
    //return Sys.OleObject("Outlook.Application.12");
  //}
//}
function CreateOutlook() {
  try {
    return new ActiveXObject("Outlook.Application");
  } catch (exception) {
    try {
      return new ActiveXObject("Outlook.Application.12");
    } catch (exception) {
      // Handle the exception here if needed
      return null;
    }
  }
}

 

 

// Returns the ContactItem object by user name
function GetContactByName(outlook, firstName, lastName, company)
{
  var ns = outlook.GetNamespace("MAPI");
  for (var j = 1; j <= ns.AddressLists.Count; j++)
  {
    var list = ns.AddressLists.Item(j).AddressEntries
    for (var i = 1; i <= list.Count; i++)
    {
      var contact = list.Item(i).GetContact(); 
      if ( contact != null &&
           contact.FirstName   == firstName &&
           contact.LastName    == lastName &&
           contact.CompanyName == company )
        return contact;
    }
  }

  return null;
}

 

// Adds a new contact
function AddContact(outlook, firstName, lastName, company, email)
{
  var contact = outlook.CreateItem(olContactItem);
  contact.FirstName     = firstName;
  contact.LastName      = lastName;
  contact.CompanyName   = company;
  contact.Email1Address = email;
  contact.Save();
}

 

// Sends a report to the user
function SendReport(outlook, firstName, lastName, company, fileNameToAttach)
{
  var contact = GetContactByName(outlook, firstName, lastName, company);
  if (contact == null)
  {
    Log.Error("User " + firstName + " " + lastName + " was not found in the address book.");
    return;
  }

 

  // Creates a new message
  var mi = outlook.CreateItem(olMailItem);

 

  // Sets the message subject
  mi.Subject = "Test Results";

 

  // Sets the message text
  mi.Body = "Hello, " + contact.FirstName + "\n" +
            "Today my regression test failed.\n" +
            "The script is attached.\n\n" +
            "Good Luck,\n" +
            "Your tester";

 

  // Specifies the destination address 
  mi.To = contact.Email1Address;

 

  // Attaches the script code
  mi.Attachments.Add(fileNameToAttach, olByValue, mi.Body.length, "Script");

 

  mi.Display(); // This line displays the new mail on screen.
                // To send the mail, use the Send method
  // mi.Send();
}

rraghvani
Champion Level 3

The coding you have provided, is that something you have written or copied it from somewhere?

 

Have you read the information that I provided in the links? and seen the code example?

@sanjayram I see that you have used an example and put your own information in it.  However "MAPI has failed" is not enough information for us. Please show the line of code where the script failed and give us the error message. 

cancel
Showing results for 
Search instead for 
Did you mean: