用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)

解决方案 »

  1.   

    JavaMail与平台关系不大,估计是环境变量的问题,楼主再查查看。
      

  2.   

    我在Linux下用mail命令直接发信没问题,说明linux的设置应该没问题,
    不知是不是在linux下启动java虚拟机时,需要加某些命令行参数?
      

  3.   

    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的设置也应该没问题
       。
      

  4.   

    问题以解决:
      在/etc/hosts文件中加入  127.0.0.1  myhostname  
    ------------------------------------------------------
    欢迎访问我的网站: 
      http://www.sohuan.com  搜换网
    ------------------------------------------------------