Monday June 06, 2005
Writing E-mails from NetBeans IDE 4.1 (Part 1)
Who says documentation sucks? If you go to the Update Center, you can install the Ant 1.6.3 documentation set. When you do this, go to Help > Help Contents and you'll find the Ant 1.6.3 Manual integrated into the NetBeans IDE helpset. Then you can browse through the tasks and concepts at your own leisure:
One thing I learnt from browsing through the Ant tasks in the documentation is that I can send myself an e-mail (with attachments) from inside Ant. This is how I do it:
<target name = "send mail" description = "send mail">
<mail mailhost="my-mailhost" mailport="my-mailport" subject="Message from Ant">
<from address="geertjan.wielenga@sun.com"/>
<replyto address="geertjan.wielenga@sun.com"/>
<to address="geertjan.wielenga@sun.com"/>
<message>You've got Ants in your Inbox!</message>
<fileset dir="dist">
<include name="**/*.zip"/>
</fileset>
</mail>
</target>
When I run the above target, I get this output in the IDE's Output window:
send mail: Failed to initialise MIME mail: javax/mail/MessagingException Sending email: Message from Ant Sent email with 1 attachment BUILD SUCCESSFUL (total time: 0 seconds)
Despite the "Failed to Initialise" message, my e-mail is sent and received without a problem. I can imagine several implementations of this functionality. For example, you could attach the above target to the -post-jar target and then e-mail a ZIP file of your project whenever you build it. Or, maybe, you could report on the server's status this way. You'd first have to write an Ant task that queries the server's status, of course, but that could be done by setting a property when a server is started (as explained here) and then testing whether it has been set or not. There are probably many other interesting ways of using the mail task. Whatever the case, browsing through the Ant documentation can be a very useful thing. Until you find out what you don't know, you don't know what you don't know, right..?
Jun 06 2005, 04:57:03 AM PDT Permalink


