Forum Discussion

juliemorris's avatar
juliemorris
Occasional Contributor
2 years ago

Emailing results error "Invalid left-hand side in assignment"

Hi,

 

I have a function in a helper file that is used by multiple projects (within the projectSuite). The code works on all except ONE project.

When debugging I get the exception: "ReferenceError: Invalid left-hand side in assignment\n at Results_SendEmail (<aq:ResultsHelper>:106:20)\n at test (<aq:ResultsHelper>:149:3)"

I cant find any differences within the project settings, and permissions on the file structure appears to be like the other projects.

 

To prove that the code runs, I am running everything from the helper file (it contains all code) and then the helper file is loaded into all projects (Add Existing). It only fails in this one project...

 

Does anyone have any ideas? I might have to recreate it in a separate project...seems silly though.

 

Thanks muchly
Julie


Below is my code that Im running.
The exception shows at the line highlighted.

To get this code to work locally - you will need to update the gmail account names and set it up to use App settings

 

function sendMyTestResults() 
{
sendEmail("myemail@gmail.com", "julie@myemail.com", "Test Results for today", "No test result today");
}


function sendEmail(mFrom, mTo, mSubject, mBody, mAttach)
{
var i, schema, mConfig, mMessage;

try
{
schema = "http://schemas.microsoft.com/cdo/configuration/";
mConfig = Sys.OleObject("CDO.Configuration");
mConfig.Fields.Item(schema + "sendusing") = 2; // cdoSendUsingPort   <<------ Exception appears after running this line
mConfig.Fields.Item(schema + "smtpusessl") = 1; // Use SSL

// If you use Gmail
// Email needs to be setup with an APP Password
mConfig.Fields.Item(schema + "smtpserver") = "smtp.gmail.com";
mConfig.Fields.Item(schema + "smtpserverport") = 465;
mConfig.Fields.Item(schema + "sendusername") = "myemail@gmail.com"; // User name (if needed)
mConfig.Fields.Item(schema + "sendpassword") = "12312312312313"; // User password (if needed)
mConfig.Fields.Item(schema + "smtpauthenticate") = 1; // Authentication mechanism
mConfig.Fields.Update();

mMessage = Sys.OleObject("CDO.Message");
mMessage.Configuration = mConfig;
mMessage.From = mFrom;
mMessage.To = mTo;
mMessage.Subject = mSubject;
mMessage.HTMLBody = mBody;

aqString.ListSeparator = ",";
for(i = 0; i < aqString.GetListLength(mAttach); i++)
mMessage.AddAttachment(aqString.GetListItem(mAttach, i));
mMessage.Send();
}
catch (exception)
{
Log.Error("Email cannot be sent", exception.description);
return false;
}
Log.Message("Message to <" + mTo + "> was successfully sent");
return true;
}

 

  • Thanks Kitt for your suggestions. 
    It turns out that this project uses Javascript vs the other projects using JScript. 
    I now have two send functions dependent on the project in use. 

  • Kitt's avatar
    Kitt
    Regular Contributor

    My first suggestion, it appears that you are not sending the appropriate parameters to your sendEmail() function - which accepts 5 parameters, and you only pass in 4:

    function sendMyTestResults() 
    { 
      sendEmail(1- "myemail@gmail.com", 2- "julie@myemail.com", 3- "Test Results for today", 4- "No test result today"); 
    }
    
    
    function sendEmail(1- mFrom, 2- mTo, 3- mSubject, 4- mBody, 5- mAttach)
    {
      // send email stuff
    }

    Double check your code and how it compares to the script examples from TestComplete [here].

     

    One easy way to quickly test SMTP communications on your machine is to open CMD and type

    telnet smtp.gmail.com 465, and if you get into telnet you have a connection.

     

    If you want to test that you can actually send mail through this port and get some better logging than the generic error your received, use this telnet guide from Microsoft ([here] - step 3).

    • juliemorris's avatar
      juliemorris
      Occasional Contributor

      Thanks Kitt for your suggestions. 
      It turns out that this project uses Javascript vs the other projects using JScript. 
      I now have two send functions dependent on the project in use.