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
End If
set MailHost to “
smtp.mydomain.com” //Replace generic SMTP address with the actual one.
set MailAuthentication to “none"
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 “” into MailBody
put “
" after MailBody
put “
" after MailBody
put “
" after MailBody
put “
" after MailBody
put “
" after MailBody
put “
" after MailBody
put “
" 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,</div>
Subject:Title,</div>
SMTP_HOST:MailHost,</div>
SMTP_TYPE:MailAuthentication,</div>
SMTP_USER:MailUser,</div>
SMTP_PASSWORD:MailPassword,</div>
“Content-Type”:MailType,</div>
Body: MailBody,</div>
Attachment: global TestResult.LogFile)
else
set Title to “FAILURE - Test”&&global TestName
sendMail (To:Recipient,</div>
Subject:Title,</div>
SMTP_HOST:MailHost,</div>
SMTP_TYPE:MailAuthentication,</div>
SMTP_USER:MailUser,</div>
SMTP_PASSWORD:MailPassword,</div>
“Content-Type”:MailType,</div>
Body: MailBody,</div>
Attachment: (ScreenError,global TestResult.LogFile))
End If
Duration: |
”&&TestDuration&&" |
Errors: |
”&&global TestResult.Errors&&" |
Exceptions: |
”&&global TestResult.Exceptions&&" |
Log File Location: |
”&&global TestResult.LogFile&&" |
Run Date/Time: |
”&&global TestResult.RunDate&&" |
Status: |
”&&global TestResult.Status&&" |
Warnings: |
”&&global TestResult.Warnings&&" |