Search code examples
robotframework

How to implement email notifications for Robot Framework test results?


I'm working with Robot Framework for automation testing and need to set up a system where an email notification is sent upon the completion of test execution. I would like some guidance on how to script this functionality. Specifically, I'm looking for advice on how to integrate email notifications that would include the test results.

What I have:

  • Access to an email server and its details.

What I need help with:

  • Example scripts or methods to send emails after Robot Framework test execution.
  • Suggestions on how to include test results in the email body

Solution

  • I use smtplib and MIMEText

    import smtplib
    from email.mime.text import MIMEText
    
    class EmailClient():
    
        def __init__(self, my_address):
            self.my_address = my_address
    
        def send(self, message, subject, user, email):
    
            header = "Hello " + str(user) + ",\n\n"
            footer = "\n\n-Your Boss"
            msg = MIMEText(header + message + footer)
    
            msg['Subject'] = subject
            msg['From'] = self.my_address
            msg['To'] = email
    
            s = smtplib.SMTP('localhost')
            s.sendmail(self.my_address, [email], msg.as_string())
            s.quit()
    
    EClient = EmailClient("[email protected]")
    EClient.send("This is a test Email", "Test Subject", "John Doe", "[email protected]")