Showing posts with label maven-postman-plugin. Show all posts
Showing posts with label maven-postman-plugin. Show all posts

2011/09/09

Sending an email using maven-postman-plugin and smtp.gmail.com

I configured maven to send a notification after deploying successfully an artifact.

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[
                    <p>Partner, we have a new deployment!</p>
                    <br>
                    <p>Have a nice day.</p>
                    ]]>
                </htmlMessage>
            </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>
    ...
    ...
    ...
</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!