使用James邮件服务器遇到问题很受伤(但是后来发现是“乌龙”,囧)
程序员文章站
2022-07-14 21:21:48
...
James2.3.2运行在ubuntu上面,ruby也在上面,本地代码测试发邮件居然错误。
Jame运行后,在里面增加两个账号paul和sandy。
smtpserver日志,AUTH method LOGIN failed这样的错误信息根本搞不清楚根本原因。
James配置,修改部分
----------------------------------------------------------------------
ruby代码
报错误
基本怀疑James auth plain有bug,没有心情去继续深入追究,换邮件服务器。
http://www.jezzper.com/jezzper/Discussions.nsf/f72637182738a22ec1257082007010ef/4baacde21bddba9dc1256f63006a6e30!OpenDocument
======================================================================
又经过一些时间分析,使用比较熟悉的Java代码来测试,发现上面的ruby代码有潜在问题,估计是协议支持问题,后续再多花时间分析。
Jame运行后,在里面增加两个账号paul和sandy。
smtpserver日志,AUTH method LOGIN failed这样的错误信息根本搞不清楚根本原因。
27/06/12 00:15:03 INFO smtpserver: SMTP Service uses default thread group. 27/06/12 00:15:03 INFO smtpserver: SMTP Service is running on: ubuntu 27/06/12 00:15:03 INFO smtpserver: SMTP Service handler hello name is: ubuntu 27/06/12 00:15:03 INFO smtpserver: SMTP Service handler connection timeout is: 360000 27/06/12 00:15:03 INFO smtpserver: SMTP Service connection backlog is: 5 27/06/12 00:15:03 INFO smtpserver: SMTP Service will allow a maximum of 30 conn ections. 27/06/12 00:15:03 INFO smtpserver: This SMTP server requires authentication, bu t doesn't verify that the authentication credentials match the sender address. 27/06/12 00:15:03 INFO smtpserver: Authorized addresses: [127.0.0.0/255.0.0.0] 27/06/12 00:15:03 INFO smtpserver: No maximum message size is enforced for this server. 27/06/12 00:15:03 INFO smtpserver: The idle timeout will be reset every 20480 b ytes. 27/06/12 00:15:03 INFO smtpserver: Added Commandhandler: org.apache.james.smtps erver.VrfyCmdHandler 27/06/12 00:15:03 INFO smtpserver: Added Commandhandler: org.apache.james.smtps erver.AuthCmdHandler 27/06/12 00:15:03 INFO smtpserver: Added Commandhandler: org.apache.james.smtps erver.QuitCmdHandler 27/06/12 00:15:03 INFO smtpserver: Added Commandhandler: org.apache.james.smtps erver.HelpCmdHandler 27/06/12 00:15:03 INFO smtpserver: Added Commandhandler: org.apache.james.smtps erver.HeloCmdHandler 27/06/12 00:15:03 INFO smtpserver: Added Commandhandler: org.apache.james.smtps erver.MailCmdHandler 27/06/12 00:15:03 INFO smtpserver: Added Commandhandler: org.apache.james.smtps erver.DataCmdHandler 27/06/12 00:15:03 INFO smtpserver: Added Commandhandler: org.apache.james.smtps erver.RcptCmdHandler 27/06/12 00:15:03 INFO smtpserver: Added Commandhandler: org.apache.james.smtps erver.EhloCmdHandler 27/06/12 00:15:03 INFO smtpserver: Added MessageHandler: org.apache.james.smtps erver.SendMailHandler 27/06/12 00:15:03 INFO smtpserver: Added Commandhandler: org.apache.james.smtps erver.NoopCmdHandler 27/06/12 00:15:03 INFO smtpserver: Added Commandhandler: org.apache.james.smtps erver.ExpnCmdHandler 27/06/12 00:15:03 INFO smtpserver: Added Commandhandler: org.apache.james.smtps erver.RsetCmdHandler 27/06/12 00:15:03 INFO smtpserver: SMTP Service started plain:25 27/06/12 00:19:54 INFO smtpserver: Connection from localhost (127.0.0.1) 27/06/12 00:21:55 INFO smtpserver: Connection from localhost (127.0.0.1) 27/06/12 00:21:55 ERROR smtpserver: AUTH method LOGIN failed 27/06/12 00:22:54 INFO smtpserver: Connection from localhost (127.0.0.1) 27/06/12 00:22:54 ERROR smtpserver: AUTH method LOGIN failed
James配置,修改部分
增加了一个servername配置 <servernames autodetect="true" autodetectIP="true"> <!-- CONFIRM? --> <servername>localhost</servername> <servername>ubuntu</servername> </servernames> 需要登录 <authRequired>true</authRequired>
----------------------------------------------------------------------
ruby代码
require 'net/smtp' msg = "Subject: Sendmail test Hi There!\n\nThis works, and this part is in the body." smtp = Net::SMTP.new 'localhost', 25 #smtp.enable_starttls smtp.start('localhost','paul@localhost', '123456', :login) do smtp.send_message(msg, 'paul@localhost', 'sandy@localhost') end
报错误
/home/lxiaodao/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/net/smtp.rb:971:in `check_auth_response': 535 Authentication Failed (Net::SMTPAuthenticationError) from /home/lxiaodao/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/net/smtp.rb:759:in `auth_login' from /home/lxiaodao/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/net/smtp.rb:735:in `authenticate' from /home/lxiaodao/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/net/smtp.rb:570:in `do_start' from /home/lxiaodao/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/net/smtp.rb:525:in `start' from localsend.rb:6:in `<main>'
基本怀疑James auth plain有bug,没有心情去继续深入追究,换邮件服务器。
http://www.jezzper.com/jezzper/Discussions.nsf/f72637182738a22ec1257082007010ef/4baacde21bddba9dc1256f63006a6e30!OpenDocument
Chris Means wrote: > I've not seen this problem mentioned before. Which tells us that AUTH PLAIN isn't in wide use. > I keep getting a SMTP Authentication Failed (535). It appears that our AUTH PLAIN implementation is wrong. Outlook works because it uses AUTH LOGIN, which we do have implemented properly. I have a fix locally, and will commit to CVS. It is a one liner, if you want to make it in your copy. > smtpserver: Command received: AUTH PLAIN Y21lYW5zAGNtZWFucwBaYXBob2Q= You do realize that you have to change your password, right? You just gave it out to everyone.
======================================================================
又经过一些时间分析,使用比较熟悉的Java代码来测试,发现上面的ruby代码有潜在问题,估计是协议支持问题,后续再多花时间分析。
public void sendlocal(String[] args){ String host = "localhost"; String from = "paul@localhost"; String[] to = {"sandy@localhost"}; // added this line if(args!=null){ to=new String[]{args[0]}; if(args.length>=2&&args[1]!=null){ from=args[1]; } } String pass = "123456"; Properties props = System.getProperties(); //props.put("mail.smtp.starttls.enable", "true"); // added this line props.put("mail.smtp.host", host); props.put("mail.smtp.user", from); props.put("mail.smtp.password", pass); props.put("mail.smtp.port", "25"); props.put("mail.smtp.auth", "true"); Session session = Session.getDefaultInstance(props, null); MimeMessage message = new MimeMessage(session); try { message.setFrom(new InternetAddress(from)); InternetAddress[] toAddress = new InternetAddress[to.length]; // To get the array of addresses for( int i=0; i < to.length; i++ ) { // changed from a while loop toAddress[i] = new InternetAddress(to[i]); } System.out.println(Message.RecipientType.TO); for( int i=0; i < toAddress.length; i++) { // changed from a while loop message.addRecipient(Message.RecipientType.TO, toAddress[i]); } message.setSubject("Sending in a group"); message.setText("Welcome to JavaMail"); Transport transport = session.getTransport("smtp"); transport.connect(host, from, pass); transport.sendMessage(message, message.getAllRecipients()); transport.close(); System.out.println("send mail correct!!"); } catch (AddressException e) { e.printStackTrace(); } catch (MessagingException e) { e.printStackTrace(); } }