Send Email

Could someone guide me with my problem.
I cannot send email, its shows 

Error Running Script Command:

sendmail Error - sendmail Failed (see console for details).

SendMail (to:"[email protected]", subject:"testsubject", message:"testmessage")

Comments

  • DaveHesterDaveHester Member ✭✭
    There are a number of parameters that you may need to add for your script to communicate with your company's mail server. My script is a bit more complicated, but hopefully, it will help you.

    //Sends an email from within a script and closes

    If global ScriptOwner is empty then
    put "[email protected]" into global ScriptOwner //Replace generic recipient email with a real one.
    End If

    set MailHost to "smtp.mydomain.com" //Replace generic SMTP address with the actual one.
    set MailAuthentication to "none"
    set MailUser to "[email protected]" //Replace generic sender email with a real one.
    set MailPassword to "myemailpassword" //Replace with sender's email password. If you choose the encrypt this password see http://docs.testplant.com/ePF/SenseTalk/stk-encrypting-text.htm for more information.
    set MailType to "text/html" //Forces email to accept HTML tags in the email body.
    put global TestResult.Duration div 60 into TestDurationInMinutes //Test results are reported in seconds. This equation calculates the time in minutes.
    put global TestResult.Duration rem 60 into TestDurationInSeconds //This equation calculates the number of seconds remaining after dividing by 60.
    put format ("%02i",TestDurationInSeconds) into TestDurationInSeconds //This forces a leading 0 for single-digit seconds.
    put TestDurationInMinutes&":"&TestDurationInSeconds into TestDuration //This concatenates minutes with seconds with a colon between.
    put global TestResult.LogFile into ScreenError  //This attaches the log file to the email.
    replace "logfile.txt" with "screen_error.png" in ScreenError //This substitutes the error screenshot for a second instance of the log file.

    //Including HTML tags in the mail body allows you to create a table in the body of the email message.
    put "<table>" into MailBody
    put "<tr><td>Duration:</td><td>"&&TestDuration&&"</td></tr>" after MailBody
    put "<tr><td>Errors:</td><td>"&&global TestResult.Errors&&"</td></tr>" after MailBody
    put "<tr><td>Exceptions:</td><td>"&&global TestResult.Exceptions&&"</td></tr>" after MailBody
    put "<tr><td>Log File Location:</td><td>"&&global TestResult.LogFile&&"</td></tr>" after MailBody
    put "<tr><td>Run Date/Time:</td><td>"&&global TestResult.RunDate&&"</td></tr>" after MailBody
    put "<tr><td>Status:</td><td>"&&global TestResult.Status&&"</td></tr>" after MailBody
    put "<tr><td>Warnings:</td><td>"&&global TestResult.Warnings&&"</td></tr>" after MailBody



    set Recipient to global ScriptOwner //References the recipient's email from above.
    set Title to "Parameterized email test" //Creates a generic subject line to test whether an email was generated outside of a script run.

    If global TestResult's Status is "success" then
    set Title to "SUCCESS - Test:"&&global TestName //Concatenates the script status (Success or Fail) with the test name from the Master Script
    sendMail (To:Recipient,\
    Subject:Title,\
    SMTP_HOST:MailHost,\
    SMTP_TYPE:MailAuthentication,\
    SMTP_USER:MailUser,\
    SMTP_PASSWORD:MailPassword,\
    "Content-Type":MailType,\
    Body: MailBody,\
    Attachment: global TestResult.LogFile)
    else
    set Title to "FAILURE - Test"&&global TestName
    sendMail (To:Recipient,\
    Subject:Title,\
    SMTP_HOST:MailHost,\
    SMTP_TYPE:MailAuthentication,\
    SMTP_USER:MailUser,\
    SMTP_PASSWORD:MailPassword,\
    "Content-Type":MailType,\
    Body: MailBody,\
    Attachment: (ScreenError,global TestResult.LogFile))
    End If


Sign In or Register to comment.