The mail is actually sent, but the Mail task claims failure. This appears to be due to send QUIT returning a blank line, which causes the mail task to generate an IndexOutOfBoundsException in line 87 of SmtpResponseReader. I believe my mail server is probably MS-Exchange pretending to be a smtp mail server. Using the MimeMail task works perfectly.
I wouldn't be all that surprised to see Exchange not following the RFCs - on the other hand, I already had to modify Jason's original code as it couldn't deal with perfectly legal continuation lines ... Can you give me the protocol of a complete SMTP session that you run by using telnet to the offending server's SMTP port? Something like Trying 127.0.0.1... Connected to localhost. Escape character is '^]'. 220 xxxxxxxxxxxxxxxx ESMTP Sendmail 8.11.6/8.11.6; Wed, 5 Dec 2001 08:45:01 +0100helo xxxxxxxxxxxxxxxx 250 xxxxxxxxxxxxxxxx Hello IDENT:0fcKw84eikv1kInYntvVQBPPFsMI8DQ8@localhost [127.0.0.1], pleased to meet you mail from: <some@legal.address> 250 2.1.0 <some@legal.address>... Sender ok rcpt to: <someother@legal.address> 250 2.1.5 <someother@legal.address>... Recipient ok data 354 Enter mail, end with "." on a line by itself Subject: Dummymail some text here . 250 2.0.0 fB57jc804797 Message accepted for delivery quit 221 2.0.0 xxxxxxxxxxxxxxx closing connection Connection closed by foreign host.
Created attachment 878 [details] log of telnet session with mailserver
Hmm, the log looks the way it should (except for some stray white space in front of your quit command). Are you sure, you are talking about Ant 1.4.1? line 87 is result.setLength(0); which shouldn't throw and IndexOutOfBoundsException (can it?). Can you give us a complete stack trace please?
The offending line is result.append(line.substring(0, 3)); which is line 87 in the source I have. Since the source can only be downloaded from the Nightly build section it is probably slightly newer than 1.4.1 But this is the staktrace I get using the a straight Ant 1.4.1 install java.lang.StringIndexOutOfBoundsException: String index out of range: 3 at java.lang.String.substring(String.java:1522) at org.apache.tools.mail.SmtpResponseReader.getResponse (SmtpResponseReader.java:87) at org.apache.tools.mail.MailMessage.send(MailMessage.java:374) at org.apache.tools.mail.MailMessage.sendQuit(MailMessage.java:368) at org.apache.tools.mail.MailMessage.sendAndClose(MailMessage.java:279) at org.apache.tools.ant.taskdefs.SendEmail.execute(SendEmail.java:246) at org.apache.tools.ant.Task.perform(Task.java:217) at org.apache.tools.ant.Target.execute(Target.java:164) at org.apache.tools.ant.Target.performTasks(Target.java:182) at org.apache.tools.ant.Project.executeTarget(Project.java:601) at org.apache.tools.ant.Project.executeTargets(Project.java:560) at org.apache.tools.ant.Main.runBuild(Main.java:454) at org.apache.tools.ant.Main.start(Main.java:153) at org.apache.tools.ant.Main.main(Main.java:176) It the substring that is throwing the IndexOutOfBounds. As will the other uses of substring, and charAt in this class, as none of them check for String length first.
OK, the sources have changed because all * imports have been changed to explicit ones - that's why the line numbers have changed. Looking at your trace, the response is longer than three characters and follows all rules for SMTP. I'll add some explicit checks, but they'll probably only lead to "protocol error" exceptions instead of this one. Could you please try the next nightly build (2001-12-11) and see what happens?
Ran with nightly build from 11-DEC-2001 Build output was: BUILD FAILED D:\source\main\buildScripts\NightlyBuild.xml:167: IO error sending mail at org.apache.tools.ant.taskdefs.SendEmail.execute(SendEmail.java:289) at org.apache.tools.ant.Task.perform(Task.java:217) at org.apache.tools.ant.Target.execute(Target.java:186) at org.apache.tools.ant.Target.performTasks(Target.java:204) at org.apache.tools.ant.Project.executeTarget(Project.java:855) at org.apache.tools.ant.Project.executeTargets(Project.java:809) at org.apache.tools.ant.Main.runBuild(Main.java:468) at org.apache.tools.ant.Main.start(Main.java:159) at org.apache.tools.ant.Main.main(Main.java:182) --- Nested Exception --- java.io.IOException: Unexpected reply to command: QUIT: at org.apache.tools.mail.MailMessage.send(MailMessage.java:412) at org.apache.tools.mail.MailMessage.sendQuit(MailMessage.java:403) at org.apache.tools.mail.MailMessage.sendAndClose(MailMessage.java:314) at org.apache.tools.ant.taskdefs.SendEmail.execute(SendEmail.java:287) at org.apache.tools.ant.Task.perform(Task.java:217) at org.apache.tools.ant.Target.execute(Target.java:186) at org.apache.tools.ant.Target.performTasks(Target.java:204) at org.apache.tools.ant.Project.executeTarget(Project.java:855) at org.apache.tools.ant.Project.executeTargets(Project.java:809) at org.apache.tools.ant.Main.runBuild(Main.java:468) at org.apache.tools.ant.Main.start(Main.java:159) at org.apache.tools.ant.Main.main(Main.java:182)
But it does send a response, doesn't it? From your trace: 221 retro.xedoc.com.au closing connection I'll see whether I can change the class so that a bad response on QUIT isn't treated as a problem - does the mail get sent?
Yeah - it sends a response. But it appears to be an empty String. The mail always gets sent.
OK, I finally changed the code to deal with errors in the QUIT command a little differently. Could you please try the nightly build 2002-01-09 and see whether the problem does away?
It's been a month now since Stefan's fix went in place. This should have fixed this issue because we haven't heard back a nagative response from William. Marking it as fixed. William, you may reopen it if the problem persists.