Geertjan's Blog

  • June 7, 2005

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

Geertjan Wielenga
Product Manager
In yesterday's blog entry I showed how you can use Ant to write and send an e-mail from NetBeans IDE 4.1 (or 4.0). However, the e-mail was hardcoded in an Ant script. Whenever you want to send an e-mail to a different person, you have to change the address in the Ant script. The same goes for the subject line and the message. Therefore, even though it's kind of cute that you can send e-mails from NetBeans IDE 4.1, via Ant, it's not very usable. However, a few blog entries ago, I outlined an Ant-prompted deployment scenario. Thanks to Ant's input handler, you're able to write an Ant script that lets you select a deployment server on the fly. That same input handler can be used, of course, for setting or selecting an e-mail address, subject line, and message body.

Here's the Ant script that makes it all possible:

<target name="Create E-mail" description="E-Mail">
<input message="Who do you want to write to?"
<input message="What should the subject line be?"
defaultvalue="E-mail from Ant"/>
<input message="What would you like to say?"
defaultvalue="Ant-integration in NetBeans IDE 4.x is great!"/>
<mail mailhost="mymailhost" mailport="mymailport" subject="${email.subject}">
<from address="geertjan.wielenga@sun.com"/>
<to address="${email.destination}"/>

Now, after hooking the above target to the IDE's Tools menu, I can choose it there:

When I choose that menu item, the first input handler pops up and I fill in the destination address:

When I click OK, the email.destination property is set. Then the next input handler appears and I fill in the subject line of my e-mail:

When I click OK, the email.subject property is set. The next input handler appears and I type in my message. Sure, the input handler is small and this whole e-mail implementation is very wobbly and anything but versatile, however it gets the job done. For sending small messages and reminders to others (or to myself) the input handler is perfect:

When I click OK in the input handler above, the email.message property is set and the mail task -- which is part of the same target -- sends the e-mail to its destination. I could also attach a logfile, for example, so this scenario could be quite a bit more useful than it might seem. Maybe it would be better to hook the target up to a simple shortcut so that I can call it really quickly whenever I want, to quickly remind myself of something while I'm in the middle of something else. And, by the way, notice that the Ant script sets a default value for each input handler.

Join the discussion

Comments ( 1 )
  • Duana Thursday, August 3, 2006
    That's cool but are you aware of any way you can have multiple inputs on the one form?
    That would probably involve writing you own InputHandler. Are you aware of any resources for doing this?
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.