Need to trigger email with failure when robot test fails


I have scenario like I have to trigger email in specific format like reason for failure, Priority etc…, whenever test fail in robot framework. Please help in getting solution


Hi Sudheer,

There are so many possible ways to solve this problem, but none are really “builtin”

How are you running your tests?

The fact that you want email notification on failure indicates that they are probably being run by some automated process?
Does that process have the ability to send email notifications? because this is the usual way to handle this type of notification.


@damies13 We are running our test script locally using Visual studio code. None are really ‘built in’ means do we need to write python code to trigger mail for the failure test case/step? Please share the ways we can achieve this.


Hi Sudheer,

As I mentioned before, most of the time this would be handled by the process that launched the test, meaning your CI/CD engine or build server. But if you are triggering the tests manually then yes you would need ti implement something.

Some examples of what you could do (there are many other options these are just a few):

  • you could use the Listener interface (yes python code) to listen for end_suite or end_test, if status is FAIL, then send the email. (I linked the documentation on how to do this)
  • You could write a keyword in python (Creating test library class or module) to send an email, then call the keyword in a test or suite teardown (Setups and teardowns) if the test/suite failed, i’d suggest having 3 arguments to the keyword, being email recipient, email subject and email body, then you can use the Automatic variables available during teardown to customise the email subject and variable, and also define in the robot test case who receives the email (different test cases might need to go to different people/teams?)

Robot framework is very flexible and can do almost anything if you set your mind to it, it’s also got really great documentation.


1 Like has an API which allows you to send emails. You can also create and save templates in SendInBlue and call those templates from the API with variable data.

Using this I trigger emails on failure from robot framework using a POST request.

A simple example RF Code:

*** Settings ***
Library  OperatingSystem
Library  RequestsLibrary
Library  Collections

*** Variable ***
${string1}  apples
${string2}  oranges

*** Test Cases ***
    IF  '${string1}'=='${string2}'
      log to console  Apples are oranges and dogs are cats and monkeys eat bananas.
      create session  email
      ${headers}=  create dictionary  content-type=application/json  accept=application/json  api-key=reallylongapikeyhere
      ${json}=  get file  failed.json
      ${response}  post on session  email  /v3/smtp/email  headers=${headers}  data=${json}
      log to console  ${response}

…and example json file which it is reading the body content from:

      "name":"Testy McTesterson",
         "name":"Your Name"
   "htmlContent":"It's broke yo."

The script generates a failure since apples do not equal to oranges, then generates the email as such:


1 Like

I think this is the right way.

I’m doing it like so:

  • let the tests run to the end
  • get output.xml and parse it using ResultVisitor
  • get all the failed and all the passed testcases
  • report this to:
    • JIRA as task/subtask (suite/testname)
    • send mattermost hook to notify users
    • send Email notification to notify users

Of course, you can handle listener, that will send information about failed test right after test fails, but for me is better to just parse output, and do other things with it, not just send email

Hi @tomaspekarovic,

Just FYI when robot exits you can catch the Return codes at the os level, if it’s 0 all the tests passed witch might be useful if you only want to notify when there is a failure.

Also catching the stdout Command line output might be useful as the email body if you just want a quick summary, might save you from processing the XML if that’s sufficient information and you just attach the xml and html files.

Hope that’s helpful,


I know :slight_smile: but I want to store all as jira tasks, every time. I just create task with suitename and date and other information. Create subtasks with timing, and if everything is ok, I just close all the taska/subtasks.
If not, failed results are assigned to specific person.
This way, i can look for all the runs in history with their specific states and even find out if it found a bug or not.
Ofc notification are sent only if there is any problem.
Also log.html is attached, but the parsed tasks gives me more freedom and statistics about runs.
If someone does not need this information it is maybe better to just get statuscode and send notification of it is error.

1 Like


I’m collecting Test status in teardown using rum keyword if test failed and if test fails it will trigger a mail with error. To trigger mail I have written python code but I want to also attach log reports generated by robot framework in the mail itself. Can we collect log reports during execution runtime?

Report files will be written as a last step of the robot run so, either in any teardown be it test or suite, the files wont be in proper shape…

Can we collect log reports during execution runtime?

Yes, via Listener interface you can collect the status but not the actual files.

1 Like