First, Thank you very much! I'm sure the user and password was right. By the error message, I read the ant source code and find execute() method in org.apache.tools.ant.taskdefs.email.EmailTask class was get an instance mailer by org.apache.tools.ant.taskdefs.email.MimeMailer or org.apache.tools.ant.taskdefs.email.UUMailer to send mail, in execute() method it check the mail encoding type first, if the encoding hasn't been set, the instance mailer would be null, then the following send() method will thows some exception. By the source code, i found if i want to use org.apache.tools.ant.taskdefs.email.EmailTask class to send mail, i must call setEncoding(Encoding encoding) method and set the mail encoding firset. Now I call this method and set the mail encoding and use the same user and password, it work ok. Best regard yours, ========================================================================= I would think and authentication error implies the wrong user name and/or password.
Have you tried to output the values of both prior sending the email? heliquan wrote: > > Hi, > I use ant in java code to send e-mail,but some error I can't find the > solution. > In java code ,I had new a "org.apache.tools.ant.taskdefs.email.EmailTask" > class object to send email, > but occur an "454 5.7.3 Client was not authenticated."excption. > > The java code like this: > Project pj=new Project(); > pj.init(); > Target tg=new Target(); > tg.setName("mail"); > tg.setProject(pj); > pj.addTarget(tg); > EmailTask mail=new EmailTask(); > mail.setMailhost("192.168.16.2"); > mail.setMailport(25); > mail.setUser("build"); > mail.setPassword("easbuildmail"); > mail.setFrom("[EMAIL PROTECTED]"); > mail.setToList("[EMAIL PROTECTED]"); > mail.setMessage("test mail"); > mail.setSubject("subject"); > mail.setProject(pj); > tg.addTask(mail); > tg.performTasks(); > tg.execute(); > > If i run the code,it would be throw the following exception : > > IO error sending mail > at > org.apache.tools.ant.taskdefs.email.PlainMailer.send(PlainMailer.java:92) > at > org.apache.tools.ant.taskdefs.email.EmailTask.execute(EmailTask.java:556) > at org.apache.tools.ant.Task.perform(Task.java:364) > at org.apache.tools.ant.Target.execute(Target.java:301) > at org.apache.tools.ant.Target.performTasks(Target.java:328) > at com.kingdee.kbs.views.MailTest.main(MailTest.java:46) > Caused by: java.io.IOException: Unexpected reply to command: MAIL FROM: > <[EMAIL PROTECTED]>: 454 5.7.3 Client was not authenticated. > at org.apache.tools.mail.MailMessage.send(MailMessage.java:445) > at org.apache.tools.mail.MailMessage.sendFrom(MailMessage.java:415) > at org.apache.tools.mail.MailMessage.from(MailMessage.java:195) > at > org.apache.tools.ant.taskdefs.email.PlainMailer.send(PlainMailer.java:44) > ... 5 more > --- Nested Exception --- > java.io.IOException: Unexpected reply to command: MAIL FROM: > <[EMAIL PROTECTED]>: 454 5.7.3 Client was not authenticated. > at org.apache.tools.mail.MailMessage.send(MailMessage.java:445) > at org.apache.tools.mail.MailMessage.sendFrom(MailMessage.java:415) > at org.apache.tools.mail.MailMessage.from(MailMessage.java:195) > at > org.apache.tools.ant.taskdefs.email.PlainMailer.send(PlainMailer.java:44) > at > org.apache.tools.ant.taskdefs.email.EmailTask.execute(EmailTask.java:556) > at org.apache.tools.ant.Task.perform(Task.java:364) > at org.apache.tools.ant.Target.execute(Target.java:301) > at org.apache.tools.ant.Target.performTasks(Target.java:328) > at com.kingdee.kbs.views.MailTest.main(MailTest.java:46) > Exception in thread "main" > > The user,password,hostip value ware right which in the java code,use a xml > file with the same value to call ant.bat,it would be ok.My os is windows > 2003, the ant version is 1.6.1 and the jdk version is 1.4.2_11. > What can I doing ? Can you help me? > > > Best regard > yours, > > >