Today we will try to understand the very important concept of Sending Email Reports through Maven from Eclipse.

We know that Maven eliminates the burden of downloading jars and adding them to the build path, instead we now add the dependences that automatically download jars from repository for us. Incase Maven is new to you, I suggest to go through the below tutorials to Learn more about Maven:


We know how much it is important to generate reports for tests we performed and also to send them to team or manager. In Selenium we have three options to notify the test results.

  1. Send mail using java code ( JavaAPI)
  2. Configure Jenkins (CI) to send the reports
  3. To use Maven Post-Man plugin to send reports using eclipse



Steps to Send Reports Automatically to Email using Maven from Eclipse

Now let us focus on the third option using Maven plug-in.To achieve the same there are following steps to perform:

  1. Create a New Maven Project
  2. Create a BasicTest to Sum two numbers
  3. Add Maven Dependencies for TestNG & ExtentReport
  4. Create TestNg Xml for the Project
  5. Add Surfire plugin
  6. Add Post-Man plugin and Run the Maven Test


Step 1: Create a New Maven Project

1: Open Eclipse Click New->Project
Send Reports Automatically to Email using Maven from Eclipse


2) Select Maven Project and then Click on Next button



3) Select Create a simple project and Click on Next



4) Enter Group Id and Artifact Id and Click on Finish. It is nothing but the Name of the Project, so this can be of your choice but I suggest to keep it same for the simplicity of this tutorial. 



5) When you click Package Explorer available on the left side of the Eclipse IDE, it will display the above created SendMavenEmail project as below




Step 2: Create a BasicTest to Sum two numbers

1) Create Package basicTests under src/test/java. Once done also create a Class file BasicTest with in that.



2) Paste the following code in the test.


3) As of now the code will show many errors in the test. It is because we have used TestNG and ExtentReport in the test and libraries for the same has not been referenced in the project. So the next step is to manage the dependencies using Maven.




Step 3: Add Maven Dependencies for TestNG & ExtentReport

1) Double Click on the pom.xml at the Project Explorer to open it. Later click n the pom.xml tab at the bottom to add dependencies.



2) Add dependencies xml code for TestNG and ExtentReport and Press CTRL + S to save the file which will automatically start downloading the jars.


The pom file will look like this now.



3) Right Click on and Click on Run as TestNG. Make sure you test get Passed and you find the report for the same.




Step 4: Create TestNg Xml for the Project

1) Create the TestNg Xml file Right Click on the BasicTest =>TestNG => Convert to TestNG



2) Edit the TestNG.xml to any name like SendEmail.xml or you can keep it as TestNG.xml. Click on finish.


Notice a new file is created at the bottom of the Project Explorer with the name testng.xml.



Step 5: Add Surfire plugin

The Surefire Plugin is used during the test phase of the build life cycle to execute the unit tests of an application. It generates reports in 2 different file formats like plain text file, xml files and html files as well. Even if you are using TestNG or Junits framework for reporting, this plugin is must to use, as it helps Maven to identify tests.

1) Add the below XML code to pom.xml.


I have named my xml file as testng.xml. In case you have given the different name, enter between <SuitexmlFile> tag.


2) We can run the xml file as Right Click by pom.xml and select Run as Maven Test.

Once the Build Succesful. It is the time to add the Post-Man plugin in pom.xml.



Step 6: Add Post-Man plugin and Run the Maven Test

The Postman plugin allows you to send emails from within your build. Goals are available to send mails if a certain condition is met during the build. Or you can just fire a mail when ever you like.

1) Add the below xml code in pom.xml to add PostMan plugin to the project.


Complete POM.xml will be as follows: