Sending Email with Ant

, Add comments

Sometimes it’s useful for an Ant script to send out an email. This can be easily done using the mail task which is part of the Core Tasks in Ant. Before using the mail task, the JavaBean Activiation Framework jar file (activation.jar), and JavaMail jar file (mail.jar) needs to be copied into the Ant lib directory. Here is a mail task example which sends an email using a GMail account.

<target name="sendmail">
  <mail
    tolist="nobody@gmail.com"
    from="nobody@gmail.com"
    subject="Email subject"
    mailhost="smtp.gmail.com"
    mailport="465"
    ssl="true"
    user="nobody@gmail.com"
    password="password">
    <message>Example email sent by Ant Mail task.</message>
  </mail>
</target>

Troubleshooting Ant mail task in Ubuntu

Failed to initialise MIME mail: org.apache.tools.ant.taskdefs.email.MimeMailer not found in java.net.URLClassLoader

If you downloaded Ant from the Ubuntu packages repository, not all the core Ant tasks are available. Download and extract Ant from the Apache Ant website.

$ wget http://www.apache.org/dist/ant/binaries/apache-ant-1.7.0-bin.tar.gz
$ tar -zxvf apache-ant-1.7.0-bin.tar.gz

Copy the ant-javamail.jar into the lib directory of the Ubuntu Ant installation

$ cp ./apache-ant-1.7.0/lib/ant-javamail.jar /usr/share/ant/lib

Failed to send email: could not instantiate ssl security provider, check that you have JSSE in your classpath

If the ssl attribute is set to true, then the Java Secure Socket Extension (jsse.jar) jar file is required, which is already part of J2SE 1.4.x and later. Ubuntu uses GNU Compiler for Java (gcj) as the default JVM which doesn’t have JSSE as the part of the distribution, therefore the jsse.jar file needs to be copied into the Ant lib directory. An alternative solution is to set the default JVM to use another Java distribution which already has JSSE bundled.

Related posts:

  1. Java Code Snippet for Sending Email using Gmail SMTP Server
  2. Problem using MySQL JDBC on Tomcat 5.5 and Ubuntu 8.04
  3. If-Else in Ant
  4. Some Useful Ant Tasks
  5. Tomcat 5.5 Doesn’t Start in Ubuntu 7.10

Comments are closed.

WP Theme & Icons by N.Design Studio
Entries RSS Comments RSS Log in