Hire a senior Perl / Python programmer today; download my up-to-date resume (PDF)
John Bokma MexIT
freelance Perl programmer

Using the Mail task in Apache Ant

Tuesday, February 21, 2006 | 13 comments

For a big Perl project I am working on for quite some time I decided to use Apache Ant for creating a distribution with all the Perl code and related files. Since Ant has a Mail task, I wanted to see if I could have the files that belonged to a distribution emailed to my customer automatically.

:
:
    <target name="mail">
        <mail mailhost="example.com" mailport="25"
            subject="Update">
            <from address="from@example.com"/>
            <to address="to@example.com"/>
            <message>Hi,

A new update has been attached to this message.

Regards,
John
</message>

        <fileset dir="${dist.dir}"/>
        </mail>
    </target>
</project>    

I tried to send an email to my test account on my own server, and when I opened the message in my mail client, Mozilla Thunderbird, I saw:

begin 644 create_dr_db.pl
M=7-E('-T<FEC=#L*=7-E('=A<FYI;F=S.PH*=7-E($1"23L*=7-E($12.CI$
M871A8F%S93HZ0V]M;6]N.PH*;7D@)$1!5$%"05-%(#T@)T12)SL*;7D@)$-/
:
:
:

Immediately after my short message. I tried to add an extra line after my name, but Thunderbird somehow didn't recognize the uuencoded data as an attachment.

Since the Ant task reported:

Failed to initialise MIME mail: javax/mail/MessagingException

I decided to download the mail.jar and activation.jar from Sun's website and copy those two jar files in the lib directory of Apache Ant in order to make sending attachments using MIME work and bypassing the default mail handling of the Mail task in Apache Ant.

And indeed, after downloading javamail-1_3_3_01.zip (which contains mail.jar), jaf-1_0_2-upd2.zip (which contains activation.jar), and copying the two jar files into the lib directory of Apache Ant, the Mail task no longer complained, and Mozilla Thunderbird was able to understand that the new mail it received had indeed attachments.

Apache Ant and MIME mail related

Also today

Please post a comment | read 13 comments, latest by Kiran | RSS feed