Writing E-mails from NetBeans IDE 4.1 (Part 1)
By Geertjan on Jun 05, 2005
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="firstname.lastname@example.org"/> <replyto address="email@example.com"/> <to address="firstname.lastname@example.org"/> <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..?