Email option in Eggplant


How to send email from eggplant.
My requirement is

  1. if script is completed then send the log report to tester
  2. if script pause then send the mail to tester

Please send me any example code.It will be very helpful for me.

  1. if script is completed then send the log report to tester

For this you will want to create a master and sub-script setup. You will have one script where you call a second script using RunWithNewResults (documented here: This will create a separate log file for the sub-script.
After the sub-script has run, you can then access the status of that run from the master script. The example below shows how this might be done, though you will add the SendMail command instead of writing back out to a data file, in order to have the log file sent to the tester:

--To call a script, run it so that it generates its own logfile, access the status, and log information based on whether or not the script run was a failure:

RunWithNewResults SomeScript
put the result into MyResults

if MyResults.status is "Failure"
	logwarning "the script failed. Making note of this in the data file."
	put MyResults into item 5 of line 10 of file "path/to/DataFile.txt"
	log "SomeScript.script succeeded. Making note of this in the data file"
	put MyResults into item 6 of line 10 of file "path/to/datafile.txt"
end if

To read about the SendMail command, please see our documentation here:

  1. if script pause then send the mail to tester

If the script is paused, then it cannot do anything until it is no longer paused.

if it is sucess or fail…I need to send mail…
where I have to place sendmail option in the above code?

Hi all, This is really helpful, Thankl you
I have a question please. How do I need to do if i dont want it override the results. I want it to increment to the next line and put another result and so on…

Thank you

When you use a “put … into …” command, it will replace the previous contents of the container. Use “put … after …” to keep the previous contents and append the new value after it.

So in this case rather than doing:

put MyResults into file "/path/to/resultfile.txt"

you might do this instead:

put MyResult & return after file "/path/to/resultfile.txt"

Note that you probably want to include “& return” as part of what you append to the file. Otherwise you’ll end up with one very long line of text in the file!