Because this is done from my home server I chose to use gmail as my smtp server:
<plugin>
<groupId>ch.fortysix</groupId>
<artifactId>maven-postman-plugin</artifactId>
<version>0.1.6</version>
<executions>
<execution>
<id>send_an_email</id>
<phase>deploy</phase>
<goals>
<goal>send-mail</goal>
</goals>
<inherited>true</inherited>
<configuration>
<mailhost>smtp.gmail.com</mailhost>
<mailport>465</mailport>
<mailssl>true</mailssl>
<mailAltConfig>true</mailAltConfig>
<mailuser>your_gmail_emailer_account@gmail.com</mailuser>
<mailpassword>your_gmail_emailer_password</mailpassword>
<from>your_gmail_emailer_account@gmail.com</from>
<receivers>
<receiver>some_receiver@mail.domain</receiver>
<receiver>some_another_receiver@gmail.com</receiver>
</receivers>
<subject>Important subject</subject>
<failonerror>true</failonerror>
<htmlMessage>
<![CDATA[
<groupId>ch.fortysix</groupId>
<artifactId>maven-postman-plugin</artifactId>
<version>0.1.6</version>
<executions>
<execution>
<id>send_an_email</id>
<phase>deploy</phase>
<goals>
<goal>send-mail</goal>
</goals>
<inherited>true</inherited>
<configuration>
<mailhost>smtp.gmail.com</mailhost>
<mailport>465</mailport>
<mailssl>true</mailssl>
<mailAltConfig>true</mailAltConfig>
<mailuser>your_gmail_emailer_account@gmail.com</mailuser>
<mailpassword>your_gmail_emailer_password</mailpassword>
<from>your_gmail_emailer_account@gmail.com</from>
<receivers>
<receiver>some_receiver@mail.domain</receiver>
<receiver>some_another_receiver@gmail.com</receiver>
</receivers>
<subject>Important subject</subject>
<failonerror>true</failonerror>
<htmlMessage>
<![CDATA[
<p>Partner, we have a new deployment!</p>
<br>
<p>Have a nice day.</p>
]]>
</htmlMessage><br>
<p>Have a nice day.</p>
]]>
</configuration>
</execution>
</executions>
</plugin>
Important:
a) Put the declaration after the deployment declaration, this way if something goes wrong the email will not be send.
b) The <inherited> mark is needed only if you put this declaration in some parent pom and another child module is the deployed one. To maintain the order you may have to put the main declaration of your deployment first in the parent pom. Remember that "The order of execution depends on the order in which the goal(s) and the build phase(s) are invoked".
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<id>upload</id>
<phase>deploy</phase>
</execution>
</executions>
</plugin>
<plugin>
<groupId>ch.fortysix</groupId>
<artifactId>maven-postman-plugin</artifactId>
<groupId>ch.fortysix</groupId>
<artifactId>maven-postman-plugin</artifactId>
...
...
...
</plugin> c) The plugin didn't work until I declared the <mailAltConfig> (check out this and this).
In my case I only send the email when "production" deployment is done (I love profiles!).
What about this?
mvn deploy -Pprod
Nice!
Hi Sir
ReplyDeleteIam trying to use this plugin to send my test case results to my email after completion of build But for successfull build i get email but when test cases fail or Build failure happens i do not get email .Can you please help me how to get email even when build fails
I use mvn clean install to run my automation test cases
Hi,
ReplyDeleteCan you please let me know. What configuration is required to get mail when build get failed.
You didn't mention which platform are you using(JUnit, TestNG). However you can call your mail class under @AfterTest annotated method. No matter test fail or pass, @AfterTest annotation will execute once before execution exit.
ReplyDelete