Forum Discussion

sri99's avatar
sri99
Occasional Contributor
9 years ago

send emails - body of the message

Hi All,

 

I have a send email script that will emails the test results with the attachment (.mht) through zip file

 

I want to have the body of the message with the below information:

 

Test : Test project name
Result: Success or Error
 
Test started: 01/01/2016 12:01:00 AM  
Test stopped: 01/01/2016 12:01:00 AM
Test duration: 1 m 5 s   

Details:
Total number of project test items: 10
Executed project test items: 10

Project Test Item Results
Passed: 10, including 0 warning(s)
Failed: 0

Please advise on how to have this info in the emails so that it wont be necassary to open the .mht attachment every time

 

Thanks in Advance!

-----------------------------------------------------------------------------------

/*****  HERE IS THE SCRIPT I AM USING  ****/

 

 var message = "Attached Test Results ";

function SendResults()
{
var ArchivePath = ""; //Project.ConfigPath + "Log\\TestResults.zip";

aqFileSystem.DeleteFolder("c:\\results\\testresults\\", true);//results /* results directory*/

ArchivePath = "c:\\results\\testresults\\TestResults.mht";
Log.SaveResultsAs(ArchivePath,2 , false);

var fileList = slPacker.GetFileListFromFolder("c:\\results\\testresults\\");
 
  slPacker.Pack(fileList, "c:\\results\\testresults\\", "c:\\results\\testresults\\TestResults.zip");

//slPacker.PackCurrentTest(ArchivePath);
  SendEmail("from@gmail.com", "to@gmail.com", "Notification - TestResults", message,
   "c:\\results\\testresults\\TestResults.zip");
}

function SendEmail(mFrom,  mTo,  mSubject,  mBody,  mAttachment)
{
  var smtpServer = "smtp.gmail.com";
  var smtpPort = 465;
  var userLogin = "username";
  var userPassword = "password";
  var autentificationType = 1;
  var connectionTimeout = 60;
  var useSSL = true;

  try {
    var schema = "http://schemas.microsoft.com/cdo/configuration/";
    var mConfig = Sys.OleObject("CDO.Configuration");
    mConfig.Fields.Item(schema + "sendusing") = 2; // cdoSendUsingPort
    mConfig.Fields.Item(schema + "smtpserver") = smtpServer;
    mConfig.Fields.Item(schema + "smtpserverport") = smtpPort;
    mConfig.Fields.Item(schema + "sendusername") = userLogin;
    mConfig.Fields.Item(schema + "sendpassword") = userPassword;
    mConfig.Fields.Item(schema + "smtpauthenticate") = autentificationType;
    mConfig.Fields.Item(schema + "smtpusessl") = useSSL;
    mConfig.Fields.Item(schema + "smtpconnectiontimeout") =connectionTimeout;
    mConfig.Fields.Update();
    
    var mMessage = Sys.OleObject("CDO.Message");
    mMessage.Configuration = mConfig;
    mMessage.From = mFrom;
    mMessage.To = mTo;
    mMessage.Subject = mSubject;
    mMessage.HTMLBody = mBody;
    
    //if(0 < mAttachment.length) {
      mMessage.AddAttachment(mAttachment);
    //}
    
    mMessage.Send();
  }
  catch(exception) {
    Log.Error("E-mail cannot be sent", exception.description);
    return false;  
  }
  Log.Message("TestResults to <" + mTo +  "> was successfully sent");
  return true;
 
}

11 Replies

  • You're not populating the body of the e-mail with the right info.

     

    mMessage.HTMLBody = mBody;

    In the send mail routine populates the e-mail body.

     

     

    You are passing that in as "message".

     

    SendEmail("from@gmail.com", "to@gmail.com", "Notification - TestResults", message,
       "c:\\results\\testresults\\TestResults.zip");

    In the above line which calls the send mail routine.

     

     

    But you are populating "message" with what looks like a heading?

     

     var message = "Attached Test Results ";

    If you want the body of the e-mail to contain your summary, you simply need to send it that info. If you want all the line breaks and spacing in there, you'll need to insert <BR> line escapes in the HTML body.

     

    • Colin_McCrae's avatar
      Colin_McCrae
      Community Hero

      I'm wondering if what you're actually trying to ask is ....

       

      "How do I parse out the results summary from the mht file and put it into the e-mail body"

       

      ?

      • sri99's avatar
        sri99
        Occasional Contributor

        Exactly..

         

        I want to parse out the results summary from the mht file and put it into the e-mail body