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

Comments:

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.

Posted by Roman Strobl on August 04, 2005 at 01:17 AM PDT #

Excellent, thanks Roman. Looking forward to your blog on this subject.

Posted by Geertjan on August 04, 2005 at 01:31 AM PDT #

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 ;-)

Posted by Sonja Löhr on September 01, 2005 at 05:56 PM PDT #

send me a manual of netbeans please

Posted by guest on October 29, 2005 at 11:23 AM PDT #

Would love to do that, but you haven't left an e-mail address. You haven't left a name either.

Posted by Geertjan on October 29, 2005 at 06:33 PM PDT #

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.

Posted by Jem Ban on November 10, 2005 at 03:02 PM PST #

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.

Posted by Geertjan on November 10, 2005 at 03:07 PM PST #

hi.. 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 Regards Manjunatha

Posted by Manjunatha on May 02, 2006 at 12:36 PM PDT #

Post a Comment:
  • HTML Syntax: NOT allowed
About

Geertjan Wielenga (@geertjanw) is a Principal Product Manager in the Oracle Developer Tools group living & working in Amsterdam. He is a Java technology enthusiast, evangelist, trainer, speaker, and writer. He blogs here daily.

The focus of this blog is mostly on NetBeans (a development tool primarily for Java programmers), with an occasional reference to NetBeans, and sometimes diverging to topics relating to NetBeans. And then there are days when NetBeans is mentioned, just for a change.

Search

Archives
« February 2015
SunMonTueWedThuFriSat
1
4
8
10
11
17
27
28
       
       
Today