Geertjan's Blog

  • June 6, 2005

Writing E-mails from NetBeans IDE 4.1 (Part 1)

Geertjan Wielenga
Product Manager
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"/>

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..?

Join the discussion

Comments ( 8 )
  • Roman Strobl Thursday, August 4, 2005
    To spread the knowledge :-) The javax/mail/MessagingException is thrown because ant requires two extra libraries to send MIME e-mails. These are mail.jar and activation.jar and can be downloaded from here and here. Once these jars are on ant's classpath the attachments will be sent correctly. Mail task works without these libraries in case you do not send attachments, otherwise these 2 jars are necessary.
  • Geertjan Thursday, August 4, 2005
    Excellent, thanks Roman. Looking forward to your blog on this subject.
  • Sonja L&ouml;hr Friday, September 2, 2005
    As I just experienced, without mail.jar and activation.jar you were also lucky to have specified from=to. I got "relay access denied" whenever I tried to mail to anything other than my own address ;-)
  • guest Saturday, October 29, 2005
    send me a manual of netbeans please
  • Geertjan Sunday, October 30, 2005
    Would love to do that, but you haven't left an e-mail address. You haven't left a name either.
  • Jem Ban Thursday, November 10, 2005
    Hi! I'm having trouble building my web application. It seems that the compiler cannot find the jar packages in the WEB-INF\\lib folder.
    First I did a cvs checkout of my project. Then I created a new project with existing source files. When Netbeans has set up the Project tree, I noticed that the jar files in my WEB-INF\\lib are not in the Libraries branch. When I build my project, I get errors in compilation that the packages does not exist.
    Could you help? Thanks.
  • Geertjan Thursday, November 10, 2005
    Sure, would love to help. What version of NetBeans are you using? What's your OS? Actually, better would be to write to nbusers@netbeans.org (go here) and ask.
  • Manjunatha Tuesday, May 2, 2006
    Actually i have problem with installing activation.jar & mail.jar to javax.mail package..
    Can u please tell me the procedure to get my mail program running
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.