Skip to main content

Weird behavior from ant mail task.

  2 posts   Feedicon  
Replies: 1 - Last Post: January 09, 2014 22:31
by: jroberts2309
showing 1 - 2 of 2
Posted: January 09, 2014 18:26 by jroberts2309
We have a homegrown ETL application that is driven using Apache Ant. This app runs various SQL scripts and then we have some SQL being executed from java (capitalizing on its threading capabilities). We’re using ant java tasks and ant exec tasks to do this. When I joined the project, this application already used JavaMail (using an Ant mail task) to send emails when an SQL failure was encountered. And our desire is that the process continue when errors occur instead of letting it crash. So the potential exists for many emails to be sent during the process.

An ant mail task was defined and the mail.jar and activation.jar were placed in the ant lib directory to allow this to occur. These are the parameters we are passing to the ant mail task:
<mail from="(RDF Build)" tolist="${ConversionSpec.emailaddress}"
subject="RDF Conversion Failure Notification" messagemimetype="text/html"
failonerror="false" mailhost="${ConversionSpec.emailhost}">
The emailhost we’re using is localhost.

My task was to change some of the java classes to also use JavaMail to send emails when we receive SQLExceptions. The properties set above are being set in java as well (email host, message type, email address, subject). I’m not having any problems getting emails sent from java. When SQLExceptions are encountered, the emails are sent and are being received.

The issue is with the ant mail – and the issue is seen depending on the type of failure that is encountered first.

If an failure is encountered in an SQL script first (before an error is encountered from java), the ant mail sends a mail. This message is displayed from ant:
[mail] Sending email: RDF Conversion Failure Notification
[mail] Sent email with 0 attachments
Then if subsequent failures are encountered, regardless of if they are from java or sql, the emails are sent and received.

However, if an error is encountered from java first, like I said, I get the emails from java. But any subsequent SQL script errors and the ant mail task gives me this message:
[mail] Sending email: RDF Conversion Failure Notification
[mail] Failed to send email

So, for example, if I were to encounter errors in this sequence: SQL failure, java error, SQL failure, java error – I get all the emails (from ant mail and java). If the sequence is java error, SQL failure, java error, SQL failure – I only get the emails from java; from ant, I get a “Failed to send email” message – no other clues.

This is my first venture into JavaMail (or any auto-mail applications) so I’m not sure if I am setting the parameters incorrectly, or differently between the two mail applications. I also do not know if this is an ant problem. At first I thought it was a jar inconsistency because the ant mail is using mail.jar and activation.jar – not sure what version of JavaMail this is. For my java class, I was using javax.mail – v1.5.1. I switched to using mail.jar in java and this did not clear up the issue.

I’m using java 1.6_12. Linux OS. Using Ant 1.6.2. (really old version and we’re planning on upgrading at some point).
Any help would be appreciated. Let me know if you need more info from me. Should I pursue this problem with Apache as a possible ant problem?


Posted: January 09, 2014 22:31 by jroberts2309
Well, I found a problem. My java classes are being executed using an ant java task and the classpath was messed up. It was referring to mail and activation jars that didn’t exist. (When I switched to the latest javax.mail.jar (v1.5.1), I never changed the classpath. I was only building the software with the new jar, not running with it.) Since my $ANT_HOME/lib contains a mail.jar and activation.jar, the ant java task was apparently referring back to them – same as ant mail uses for sending it’s emails. Once I fixed the classpath to refer to the javax.mail.jar, I now receive emails from both sources regardless of sequence. But I’m not exactly sure why using the same jars would be problematic – there must be some settings that are inherently different between the two.
Replies: 1 - Last Post: January 09, 2014 22:31
by: jroberts2309
Please Confirm