最近在用javamail通过exchange发邮件时遇到了问题.大家有没有遇到过呢? 帮忙看看.非常感谢
我代码如下:
public static void main(String[] args) {
try {
String STMP="mail.df.com.cn";
final String username = "[email protected]";//该用户是exchange上面的用户
final String password = "000000";
String port="465";
  Properties props = System.getProperties();
  props.setProperty("mail.smtp.host",STMP);
 //props.setProperty("mail.smtp.port", port);
 //props.setProperty("mail.smtp.socketFactory.port", port);
 props.put("mail.smtp.auth", "true");
  props.put("mail.smtp.starttls.enable", true);
     
  Session session = Session.getDefaultInstance(props, new Authenticator(){
      protected PasswordAuthentication getPasswordAuthentication() {
          return new PasswordAuthentication(username, password);
      }});   Message msg = new MimeMessage(session);
  msg.setFrom(new InternetAddress());
  msg.setRecipients(Message.RecipientType.TO,
    InternetAddress.parse("[email protected]",false));
  msg.setSubject("Hello");
  msg.setText("Hello");
  msg.setSentDate(new Date());
  Transport.send(msg);
  
  System.out.println("Message sent success");
} catch (Exception e) {
e.printStackTrace();
}
}
但是运行的时候总是报错.错误如下:
javax.mail.SendFailedException: Sending failed;
  nested exception is:
class javax.mail.SendFailedException: Invalid Addresses;
  nested exception is:
class javax.mail.SendFailedException: 550 5.7.1 Unable to relay for [email protected]

解决方案 »

  1.   


     msg.setRecipients(Message.RecipientType.TO, 
        InternetAddress.parse("[email protected]",false)); 
    改成
     msg.setRecipients(Message.RecipientType.TO,new InternetAddress("[email protected]"));试试。
      

  2.   

    不行,我感觉是没有连接到exchange邮件服务器.
      

  3.   

    不行,我感觉是没有连接到exchange邮件服务器.
      

  4.   

    呵呵,我们无法根据你给出的域名进行解析,你先telnet mail.df.com.cn 465试试,能通吗?如果能通然后你再用smtp协议法一封邮件,是不是能成功。如果都能成功那就是程序问题了。慢慢调吧哈。