Mail-maven-plugin

From Evgeny Goldin

(Redirected from Maven-mail-plugin)
Jump to: navigation, search

Contents

Introduction

There are situation when we need e-mails to be sent as result of our build process. While CI servers like Hudson already send e-mails with jobs status, occasionally, we may need something more. We may want to get a detailed results of our integration tests by mail. Or some special kind of compilation or build process to be sent to another group. Something that is more detailed and much more informative than a simple "Build passed/failed" message from a CI server.

This plugin allows you to send emails from Maven via SMTP server:


<plugin>
    <groupId>com.github.goldin</groupId>
    <artifactId>mail-maven-plugin</artifactId>
    <version>0.2.5</version>
    <executions>
        <execution>
            <phase>install</phase>
            <goals>
                <goal>send</goal>
            </goals>
            <configuration>
                <smtp>smtp.server</smtp>
                <from>your@from.email</from>
                <mails>
                    <to>some@email;some@other.email</to>
                </mails>
                <subject>This is subject</subject>
                <text>And this is body</text>
                <files>
                    <file>fileToAttach.txt</file>
                    <file>anotherFileToAttach.txt</file>
                </files>
            </configuration>
        </execution>
    </executions>
</plugin>


Details

Provided By
Mailing List Nabble
Source Code GitHub
License
GroovyDoc <groovydoc>
Issue Tracker YouTrack
Build Server Maven
TeamCity
Maven Coordinates
  • com.github.goldin:mail-maven-plugin:0.2.5
Goal
  • send
Default Phase
  • install
Maven Repository Artifactory Online


<configuration>

<runIf> Optional. Specifies if plugin needs to be run, see "copy-maven-plugin" documentation for more details
<smtp> Specifies your SMTP server, assumes there's no SMTP Authentication
<from> Specifies your "From" address
<mails> Specifies addresses to send e-mails to. <to>, <cc>, and <bcc> nested tags are supported

<to>

<cc>

<bcc>

;-separated list of "To", "Cc", and "Bcc" addresses.

Full names can be specified as "Name &lt;mail@address&gt;":

<to>
    FirstName SecondName &lt;some@email&gt;;
    FirstName SecondName &lt;some@other.email&gt;;
    ...
</to>
<cc>
    some@email;some@other.email;and.another@email
</cc>
<bcc>
    FirstName SecondName &lt;some@email&gt;;
    FirstName SecondName &lt;some@other.email&gt;;
    ...
</bcc>
<subject> Specifies message subject, empty by default
<text> Specifies message body, empty by default
<textFile> Specifies message body as a text file, appended to <body>:
<textFile>../somewhere/body.txt</textFile>
<files> Specifies files to attach to the message:
<files>
    <file>../some/file.txt</file>
    <file>../some/other/file.txt</file>
</files>


Dynamic content: <subject>, <text>

It is easy to send e-mails with static <subject> or <text> known in advance. But what if they dynamic and depend on previous steps? In this case we need to create a corresponding Maven properties before "mail-maven-plugin" is run and make it use them:


<configuration>
    <smtp>${smtp.server}</smtp>
    <from>${from}</from>
    <mails>
        <to>${cm.mails}</to>
    </mails>
    <subject>${mail.subject}</subject>
    <text>${mail.body}</text>
    <textFile>${mail.bodyFile}</textFile>
    <files>
        <file>${status.file}</file>
    </files>
</configuration>


The idea of creating new properties dynamically is borrowed from Ant where lot's of its tasks create new Ant properties as a result of their run. Those new properties are later used for different purposes.

Same idea applies here:

  1. You run something that creates new Maven properties. It can be done with "properties-maven-plugin".
  2. You run "mail-maven-plugin" that uses those properties.


Dynamic content: <textFile>, <files>

For <textFile> and <files> you may use files whose content is created dynamically by attaching a file like "${project.build.outputDirectory}/status.txt" and making sure it contains the relevant content when "mail-maven-plugin" is run. Right now it is not possible to alter <files> list dynamically.

Personal tools