Forum Discussion

sandysang's avatar
sandysang
Contributor
10 months ago
Solved

Sending email by scirpt failed because socket error :10060, connect timeout

Hi ,

I want to ask you one question about send email by script 

ToAddressRequired. The email address to which the message will be sent.
FromHostRequired. The host from which the message will be sent.
FromNameRequired. The "user-friendly" name of the email sender.
FromAddressRequired. The email address from which the message will be sent.
SubjectRequired. The message subject.
BodyRequired. The message body.
FileName1, FileName2 … FileNameNOptional. The full paths to the files you want to send with the message.

I following above parameters but test failed, and tell me connect timeout, and we use scirpt from other project need to config mailserver ,so I want to know , should we config mailserver by scirpts?

 

  • Follow the example shown here Sending Email From Scripts, fill in the appropriate parameters but ignore FileName1. Test the email to see if it works. 

     

    If it doesn't work, regardless of what parameters you use, then your SMTP Server is not configured to allow unauthenticated emails to be sent.

11 Replies

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    I suggest you read and understand what XML is, and what HTML is first. Then think about parsing XML data to HTML readable format, which can be done via PowerShell.

     

    The command line that I had provided in my previous response, has the parameter which creates the HTML report.

     

    Create a small TestComplete project, with simple functions that outputs Log.Message, Log.Warning and Log.Error. The use the command line that I had provided against this project, so that you can see what output results it generates.

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    Follow the example shown here Sending Email From Scripts, fill in the appropriate parameters but ignore FileName1. Test the email to see if it works. 

     

    If it doesn't work, regardless of what parameters you use, then your SMTP Server is not configured to allow unauthenticated emails to be sent.

  • Hi rraghvani,

     

    Thank you for your answer, and at last we write python script to resolve it . 

    I want to know how to save all the test result by command line or by python scripts ? so that I want to send the result as attachment ?

     

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    Note, there is a size limit when sending emails.

     

    See TestComplete Command Line, parameter /ExportSummary. You can export the results to a shareable location, and then within your email create a link to point to the shareable location.

     

    You can also, export XML results, then translate the file into HTML, and send that via email.

    There's plenty of examples on the internet, in converting XML to HTML using PowerShell.

    • sandysang's avatar
      sandysang
      Contributor

      hi  rraghvani,

       

      I'm sorry to trouble you again , the result which you show as above about send email is I needed. and I try to use powershell to translate xml to html , but failed , 

      PS C:\Users\hlcla02> ConvertTo-Html -InputObject E:\AutomationTest\APPLE\report_test\20230719141607.xml Out-File E:\AutomationTest\APPLE\20230719\output.html
      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
      <html xmlns="http://www.w3.org/1999/xhtml">
      <head>
      E:\AutomationTest\APPLE\20230719\output.html
      </head><body>
      <table>
      </table>
      </body></html>

      so , could u give me some demo script to let me know how to translate xml to html? I am not sure which command is right.

      Many Thanks

  • Hi rraghvani,

    Thanks for your answer, I still meet some issue when I want to send report 

    I use python module email to send the report , and I want to create file folder and file name according date time ,and when I create batch file as bellow :

     

    Echo off
    setlocal
    :: Create folder with date
    set date=%date:~10,4%%date:~4,2%%date:~7,2%
    set folder_path=E:\AutomationTest\APPLE\%date%
    md %folder_path%
    :: Create file with date
    set time=%time:~0,2%%time:~3,2%%time:~6,2%
    set file_name=%date%%time%.xml
    set file_path=%folder_path%\%file_name%
    echo %file_path%
    endlocal
    "c:\Automation\x64\Bin\TestComplete.exe" "E:\AutomationTest\APPLE\AppleWMS_Test\AppleWMS_Test.pjs" /run "/project:Apple_Test" /ExportSummar:"E:\AutomationTest\APPLE\sandy.xml" /SilentMode /exit

     

    when I use this command to lauch test, it can run test , but can not create file as sandy.xml under the folder which exportsummar show, I don't know why? and if I use export log want to create html file directly , it will not run the test 

    By the way if I use power shell to send report , I can write the script under script ? (now send email I just write python script under scirpt folder), could u give me some suggesstion ?

     

  • Hi rraghvani

    ignore above email I find the reason, but my question is that if I use bat file to export the xml according create file folder and file , how can i use this xml file to send the report as you show me ? could u give me some suggestion?

    about xml is define in bat file , how can i use power shell to do that ? 

     

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    An example command line is,

    "c:\Program Files (x86)\SmartBear\TestComplete 15\x64\Bin\TestComplete.exe" "c:\Temp\Number\Number.pjs" /run /exit /project:Number /donotshowlog /ExportLog:C:\Temp\Number\index.html /ExportSummary:"C:\Temp\Number\SummaryReport.xml"

    index.html shows,

    SummaryReport.xml shows,

    There's plenty of examples on the internet if you search for "powershell convert xml to html".

     

    I use PowerShell to run all my automation scripts.

  • could u give me detail code about how to create html report  if it is possible? I am not know power shell ,thank you 

  • hi rraghvani ,

    Thanks for your answer, so I guess I need to create html style then import xml'data into html ?

    I try it 

     
    $beginning = {
    '<html>
    <head>
     
    <meta charset="utf-8" />
    <title>Apple_Report</title>
    <STYLE type="text/css">
    h1 {font-family:SegoeUI, sans-serif; font-size:30}
    th {font-family:SegoeUI, sans-serif; font-size:20}
    td {font-family:Consolas, sans-serif; font-size:16}
     
    </STYLE>
     
    </head>
     
    <h1>Report</h1>
    <table border="1">
    <tr>
    <th>
    testname
    </th>
        <th>
    tests
    </th>
    <th>
    failures
    </th>
    <th>
    error
    </th>
    <th>
    time
    </th>
    <th>
    timestamp
    </th>
    </tr>
    '
    }
     
    $end = {
    '
    </table>
    </html>
    </body>
    '
    }  
     
    $process = {
     
        $name=$_.name
    $tests=$_.tests
    $failures=$_.failures
    $errors=$_.errors
    $timestamp=$_.timestamp
     
    '<tr>'
        '<td>{0}</td>' -f $name
    '<td>{0}</td>' -f $tests
    '<td>{0}</td>' -f $failures
    '<td>{0}</td>' -f $errors
    '<td>{0}</td>' -f $time
    '<td>{0}</td>' -f $timestamp
    '</tr>'
    '<tr>'
    '<td>{0}</td>' -f $test_cases
     
    }
     
     
    $xmldata =[XML](Get-Content E:\AutomationTest\APPLE\sandy_test.xml -Encoding UTF8)
    $points=$xmldata.testsuites.testsuite
     
     
    $points |ForEach-Object -Begin $beginning -Process $process -End $end |Out-File -FilePath E:\AutomationTest\APPLE\sandy_test.html -Encoding utf8
    and I can create html file now ,but I don't know how can i  do next step step to send email ? could u tell me how you do it ? before I just use python to send email but how can I deal with create html style and run powshell command ? does testcomplete can run it diectly ?

     

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    I use PowerShell script to run my entire process, that's to perform a clean up, download the latest source files from the repository, run that automation using TestExecute, and then send results via email. This is all done on a separate machine.

     

    See How to send email with PowerShell - learn how to send email via PowerShell. The email body can be either plain text or HTML.