Forum Discussion

Ravikaanth's avatar
Ravikaanth
Contributor
2 years ago

Unable to send an email through SendMail() using JavaScript

Hi Team,

 

I am facing issues while sending a file through email in TestComplete. Please check the below error,

"The files you want to attach to the message do not exist."

 

Please check the below code,

if (BuiltIn.SendMail("firoz.khan@squaredatalabs.com", "smtp.hostinger.com", "Ravikaanth N S", "ravikaanth.ns@squaredatalabs.com", "Test Report", "Please find the attached report", "C:\\Users\\ravikaanth.ns\\Desktop\\TestDoc.txt", 587, true))
{
Log.Message("Mail was sent");
}
else
{
Log.Warning("Mail was not sent");
}

7 Replies

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    Can you try without file attachments e.g.

    BuiltIn.SendMail("firoz.khan@squaredatalabs.com", "smtp.hostinger.com", "Ravikaanth N S", "ravikaanth.ns@squaredatalabs.com", "Test Report", "Please find the attached report");

     

    If it fails to send an email, then your SMTP server is not allowing unauthenticated emails to be sent. You will need to consult with your IT to resolve this.

    • Ravikaanth's avatar
      Ravikaanth
      Contributor

      The below code is throwing Socket error, to overcome that we have added port number and TLS encryption.

       

      BuiltIn.SendMail("firoz.khan@squaredatalabs.com", "smtp.hostinger.com", "Ravikaanth N S", "ravikaanth.ns@squaredatalabs.com", "Test Report", "Please find the attached report");

       

      Also I tried without adding the file. That time also I got the same error "The files you want to attach to the message do not exist."

       

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    That parameters "587" and "true", what are they used for?

    • Ravikaanth's avatar
      Ravikaanth
      Contributor

      rraghvani 587 - port number of SMTP 

      true - TLS encryption, These two parameters helps to avoid socket error. 

    • Ravikaanth's avatar
      Ravikaanth
      Contributor

      rraghvani I tried by adding the file path at the end but still facing the same error "The files you want to attach to the message do not exist." I have checked the file is whether present in that location or not, everything looks good, but still I'm confused Why I'm getting this error

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    Adding port number and TLS encryption to the last parameters of BuiltIn.SendMail method will not work. As the remaining parameters only accepts files.

     

    I suggest you also try the examples given in Sending Email From Scripts

     

    If it fails to send an email, then your SMTP server is not allowing unauthenticated emails to be sent.