Forum Discussion

charles2's avatar
charles2
New Member
7 years ago

How to email the test result report as an attachment?

Hi,
I need to email the test result report in ReadyAPI but sendMail test step does not support the attachment. Is there any alternative way to do this job? 

1 Reply

  • New2API's avatar
    New2API
    Frequent Contributor

    Hi Charles, I am using ant mail via groovy.

     

    you would need to download following jars and copy it to ReadyAPI/Lib folder.

    ant.jar

    ant-javamail.jar

    ant-launcher.jar

     

    Also you will need to provide SMTP gateway config sucha as email host, port etc.

     

    Below is my script to send an html report as an attachment.

    import org.apache.tools.ant.*
    
    //preparing an email notification
    def ReportDir = context.expand ('${#Project#TestReportPath}')
    def emailHost = context.expand ('${#Global#emailHost}')        
    def fromEmail = context.expand ('${#Project#FromAddress}') 
    def toEmail = context.expand ('${#Project#ToAddress}')
    def ccEmail = context.expand ('${#Project#CcAddress}') 
    
    
    //Sending an email notification 
    
    def ant = new AntBuilder()
        ant.mail(mailhost:"${emailHost}", messagemimetype:'text/html', subject:"TestReport: APIs Functional tests", tolist:toEmail, cclist:ccEmail){
                     from(address:"${fromEmail}")
                     message("Please find the attachment for API Functional Test Report.")
                     attachments(){
                                   fileset(dir:"${ReportDir}"){
                                                               include(name:"TestReport-APIFunctionalTests.html")
                                   }
                     }
        }

    hope this helps!

     

    Best.