注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

和申的个人主页

专注于java开发,1985wanggang

 
 
 

日志

 
 

javax.mail.MessagingException: 500 Error: bad syntax linux机器上奇怪的错误  

2010-12-24 14:49:10|  分类: 项目开发 |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |
在linux下遇到这个奇怪的问题:
首先取得当前主机的主机名
>hostname
xxxx
-----------
xxxx为hostname例如 myhostname
可以得到 linux的主机名
>hostname -i
却得不到ip
正常的应该为
hostname -i
127.0.0.1
---------------------------------------------------------------
需要配置主机名
在/etc/hosts文件中加入     127.0.0.1     myhostname 
  myhostname即为上面用》hostname命令得到的名字
下面为在抄的原因

When looking at the mentioned javadocs I found

mail.smtp.localhost String Local host name used in the SMTP HELO or EHLO command. Defaults to “InetAddress.getLocalHost().getHostName()”. Should not normally need to be set if your JDK and your name service are configured properly.
Okay, following that hint I tried a quick coded test program:





用个小程序来验证一下

Okay, following that hint I tried a quick coded test program:



import java.net.*;
public class test {
public static void main ( String [] args ) {
try {
System.err.println( InetAddress.getLocalHost().getHostName() );
} catch ( Exception e ) {
e.printStackTrace();
}
}
}

When running it: boing!:

(I replaced my domain name).)

这个是hostname配置有问题的

formel5@gruender-mv:~/domains/gmv$ java test
java.net.UnknownHostException: mydomain: mydomain
at java.net.InetAddress.getLocalHost(InetAddress.java:1191)
at test.main(test.java:5)

配置一下hostname

Okay. need to fix my /etc/host: added mydomain (And talk to mydomain   )

这个是正常的

formel5@gruender-mv:~/domains/gmv$ java test
mydomain


Fine. Now I restarted my newsletter webapp without any problems

=========================================================================
=========================================================================

报的异常
org.springframework.mail.MailSendException; nested exceptions (0) are:
Caused by:
javax.mail.MessagingException: 500 Error: bad syntax

        at com.sun.mail.smtp.SMTPTransport.issueCommand(SMTPTransport.java:1363)
        at com.sun.mail.smtp.SMTPTransport.helo(SMTPTransport.java:838)
        at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:375)
        at javax.mail.Service.connect(Service.java:275)
        at org.springframework.mail.javamail.JavaMailSenderImpl.doSend(JavaMailSenderImpl.java:382)
        at org.springframework.mail.javamail.JavaMailSenderImpl.send(JavaMailSenderImpl.java:335)
        at org.springframework.mail.javamail.JavaMailSenderImpl.send(JavaMailSenderImpl.java:331)
        at com.my163.framework.mail.SendMail.sendMail(SendMail.java:205)
        at com.my163.framework.mail.SendMail.sendMailAsHtml(SendMail.java:96)
        at mail.SendPasswordByMail.sendOpenPwd(SendPasswordByMail.java:41)
        at _jsp._testmail__jsp._jspService(_testmail__jsp.java:46)
        at com.caucho.jsp.JavaPage.service(JavaPage.java:61)
        at com.caucho.jsp.Page.pageservice(Page.java:578)
        at com.caucho.server.dispatch.PageFilterChain.doFilter(PageFilterChain.java:192)
        at filter.AuthorFilter.doFilter(AuthorFilter.java:58)
        at com.caucho.server.dispatch.FilterFilterChain.doFilter(FilterFilterChain.java:73)
        at com.caucho.server.webapp.WebAppFilterChain.doFilter(WebAppFilterChain.java:175)
        at com.caucho.server.dispatch.ServletInvocation.service(ServletInvocation.java:240)
        at com.caucho.server.http.HttpRequest.handleRequest(HttpRequest.java:263)
        at com.caucho.server.port.TcpConnection.run(TcpConnection.java:481)
        at com.caucho.util.ThreadPool$Item.runTasks(ThreadPool.java:685)
        at com.caucho.util.ThreadPool$Item.run(ThreadPool.java:607)
        at java.lang.Thread.run(Thread.java:619)
===========================================

Almost everything worked fine except the newsletter tool. Looking at the catalina.log I found the following stacktrace:

javax.mail.MessagingException: 501 Syntactically invalid HELO argument(s)
at com.sun.mail.smtp.SMTPTransport.issueCommand(SMTPTransport.java:1308)
at com.sun.mail.smtp.SMTPTransport.helo(SMTPTransport.java:785)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:327)
at javax.mail.Service.connect(Service.java:236)
at javax.mail.Service.connect(Service.java:137)
at javax.mail.Service.connect(Service.java:86)
======================================================
======================================================

javamail中文问题二:机器名中含中文字符时发不出信

如果机器名是主文,发信时会报错:

EHLO
501 Syntax: EHLO hostname
HELO
501 Syntax: HELO hostname
javax.mail.MessagingException: 501 Syntax: HELO hostname

at com.sun.mail.smtp.SMTPTransport.issueCommand(SMTPTransport.java:1363)
at com.sun.mail.smtp.SMTPTransport.helo(SMTPTransport.java:838)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:375)
at javax.mail.Service.connect(Service.java:275)
at javax.mail.Service.connect(Service.java:156)
at mail.TestMail.sendMail(TestMail.java:108)
at mail.TestMail.main(TestMail.java:35)

解决方法很简单,只需要这样:
Properties props = System.getProperties();
...
props.put("mail.smtp.localhost", "localhost"); // 机器名。

========
相关链接:

javax.mail: 501 Syntactically invalid HELO argument(s)


http://www.cosmocode.de/en/blog/detman/2007-03/01-javax.mail-501-syntactically-invalid-helo-argument-s

Linux操作系统主机名(hostname)简说(v0.1b)

http://www.linuxsir.org/main/node/222


统计信息唧唧歪歪唧唧网ggyygg.net
  评论这张
 
阅读(6777)| 评论(0)
推荐 转载

历史上的今天

在LOFTER的更多文章

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2016