Thursday, April 10, 2008

You used it for what?

I'm the king of using tools for purposes they were not intended to serve, so (almost) no apologies for this one. I was trying to learn some about ant, and was flipping through some doc looking for ways it would make my life easier. I don't have large builds that need to be automated, or significant deploys, or basically any of the reasons a normal person would use ant. What I do have is the occasional "need" to email a file to someone coupled with a strong dislike for how the navigation to that file works when attaching it in Notes. Enter ant.

First, I setup windows to open the .ant extension with the ant interpreter:
  • Open Explorer
  • Select Tools->Folder Options
  • Select the File types tab
  • If ant is not present, click New.
  • Select the ant entry, and click advanced
  • In the edit file type dialog, select new action
  • Enter "open" (no quotes) for the action
  • For application used, enter (with quotes) "C:\apache-ant-1.6.5\bin\ant.bat" -file "%1"
I have a shortcut with the following target in my Windows Explorer Send To menu:
C:\apache-ant-1.6.5\bin\ant.bat -f c:\utils\testing\ant\ant_mail.ant -Dfilename= 

It's important to note that the -Dfilename= doesn't hard code the file name because it is fed to the shortcut when you do the Send To.

Here's the script it calls (ant_mail.ant):

<project name="ant_mail_file" default="mail_success" basedir="c:\utils\testing\ant">
<property file="ant_mail.properties" />
<description>Email a file passed as a parameter</description>
<target name="mail_success">
<mail mailhost="mailhost.mydomain.com" mailport="25" subject="${filename} ${subject}">
<from address="${from_address}"/>
<replyto address="${from_address}"/>
<to address="${to_address}"/>
<message>Attached is ${filename}</message>
<fileset file="${filename}">
</fileset>
</mail>
</target>
</project>


Finally, I have the following ant_mail.properties file in the same directory as ant_mail.ant:

subject=
from_address=john.mcdevitt@mydomain.com
to_address=john.mcdevitt@mydomain.com


If I'm planning ahead (rarely), I can mess with the addresses or the subject properties to make the email a little more meaningful than just having a subject line of the file name. However, the main goal is served, I can easily forward the message to whomever I wanted to send the doc to, and I get to avoid the ugly Notes attachment interface.

2 comments:

The Don said...

You are a picky, picky young man.

Anonymous said...

Talk about a typical engineer thing to do! Very you. Note to ISSS database, ANT support, OTHER category: John McDevitt.

counter free hit invisible