Tuesday, August 12, 2008

Missing Groovy Recipe: Send e-mail from Groovy

This seems to be missing in Groovy Recipes collection -- sending e-mail easily with Gant.

//----------------------------------------------------------------------------------
// using AntBuilder; for more info, see:
// http://ant.apache.org/manual/CoreTasks/mail.html
ant = new AntBuilder()
ant.mail(mailhost:'smtp.myisp.com', mailport:'1025', subject:'Test build'){
from(address:'config@myisp.com')
replyto(address:'me@myisp.com')
to(address:'all@xyz.com')
message("The ${buildname} nightly build has completed")
attachments(){ // ant 1.7 uses files attribute in earlier versions
fileset(dir:'dist'){
include(name:'**/*.zip')
}
}
}

2 comments:

Viraf said...

Have you looked at the Grails Mail Plugin to accomplish this instead of using AntBuilder. The recipe you provided is definitely usable though.

Seymour Cakes said...

Hi Visaf,

I use the mail plugin all the time, but it's only for grails -- there are many cases where I need it for normal groovy script.

It's be cool to a simple mail lib for groovy though.