Linux下JavaMail的奇怪问题!!!!

shuangsa 2006-06-24 08:22:33
用JavaMail编写的邮件发送程序,在windows下一切正常,
但在linux下却怎么也发送不了邮件,出现如下异常:
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:297)
at javax.mail.Service.connect(Service.java:156)
at javax.mail.Service.connect(Service.java:105)
at javax.mail.Transport.send0(Transport.java:168)
at javax.mail.Transport.send(Transport.java:98)
at org.wuyuan.mail.SendMail.sendMail(SendMail.java:87)
at org.wuyuan.mail.SendMail.main(SendMail.java:29)
...全文
428 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
shuangsa 2006-06-28
  • 打赏
  • 举报
回复
问题以解决:
在/etc/hosts文件中加入 127.0.0.1 myhostname


------------------------------------------------------
欢迎访问我的网站:
http://www.sohuan.com 搜换网
------------------------------------------------------
wuyg719 2006-06-26
  • 打赏
  • 举报
回复
shuangsa 2006-06-26
  • 打赏
  • 举报
回复
在线等待!请高手解答。。。
shuangsa 2006-06-26
  • 打赏
  • 举报
回复
1、代码如下:
private Session getMailSession(){
Properties props = new Properties();
props.put("mail.transport.protocol", "smtp");
props.put("mail.smtp.host", "smtp.126.com");
props.put("mail.smtp.port", "25");
props.put("mail.smtp.auth", "true");
return Session.getInstance(,
new Authenticator(){
public PasswordAuthentication getPasswordAuthentication(){
return new PasswordAuthentication("***","***");
}
}
);
}

public void sendMail(String to, String subject, String content){
try {
Message msg = new MimeMessage(getMailSession());
msg.setFrom(new InternetAddress(mailProps.getProperty("from")));
msg.setRecipient(Message.RecipientType.TO, new InternetAddress(to));
msg.setSentDate(new Date());
msg.setSubject(subject);
msg.setText(content);
Transport.send(msg);
log.debug("Send mail to: "+to);
} catch (MessagingException e) {
e.printStackTrace();
log.error(e);
}
}

2、代码很简单,应该没问题,在windows下能发送邮件,测试通过,
但在Linux下就是发不出邮件,出现异常如下:
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:297)
at javax.mail.Service.connect(Service.java:156)
at javax.mail.Service.connect(Service.java:105)
at javax.mail.Transport.send0(Transport.java:168)
at javax.mail.Transport.send(Transport.java:98)
at org.wuyuan.mail.SendMail.sendMail(SendMail.java:87)
at org.wuyuan.mail.SendMail.main(SendMail.java:29)

2、在linux下用telnet发送邮件没问题,所以linux的设置也应该没问题
。。。。
wts173 2006-06-26
  • 打赏
  • 举报
回复
up
infowain 2006-06-25
  • 打赏
  • 举报
回复
把你的问题描述详细一点吧
代码?
完整的错误信息?
shuangsa 2006-06-25
  • 打赏
  • 举报
回复
我在Linux下用mail命令直接发信没问题,说明linux的设置应该没问题,
不知是不是在linux下启动java虚拟机时,需要加某些命令行参数?
mq612 2006-06-24
  • 打赏
  • 举报
回复
JavaMail与平台关系不大,估计是环境变量的问题,楼主再查查看。

62,616

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧