Exception in thread "main" javax.mail.SendFailedException: Invalid Addresses;
  nested exception is:
class com.sun.mail.smtp.SMTPAddressFailedException: 551 User not local; please try <forward-path> at com.sun.mail.smtp.SMTPTransport.rcptTo(SMTPTransport.java:1130)
at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:525)
at javax.mail.Transport.send0(Transport.java:151)
at javax.mail.Transport.send(Transport.java:80)
at com.me.util.mail.MailExample.main(MailExample.java:48)
我在写发送邮件时的错误信息,请各位帮忙指点,谢谢

解决方案 »

  1.   

    MTA服务有个open relay的属性,如果关闭的话就只能允许本站的用户发信。
    你发信的测试用户密码是不是属于本站的,如果你是利用了别人的MTA发信而别人的MTA的open relay属性为false的话就会出错.
      

  2.   

    你看看package com.east.email;import java.util.Date;
    import java.util.Properties;import javax.mail.Session;
    import javax.mail.Transport;
    import javax.mail.internet.InternetAddress;
    import javax.mail.internet.MimeMessage;
    import javax.mail.*;
    import javax.mail.internet.*;
    import javax.activation.*;public class SendMail {
     private static MailAuthenticator autherticator=null;
     public static void main(String[] args) {
      for (int i=0;i<5;i++){
     
    String from="[email protected]";
    String to="[email protected]";
    String smtpServer="smtp.163.com";
    String subject="Hello ,this is a email Test!!";
    String content ="Welcome to you!!";
    Properties props = System.getProperties();

    props.put("mail.smtp.host", smtpServer);
    props.put("mail.smtp.auth","true");
    autherticator = new MailAuthenticator("[email protected]","123");
        Session session = Session.getDefaultInstance(props,autherticator);
        MimeMessage msg = new MimeMessage(session);
        try{
           msg.setFrom(new InternetAddress(from));
           msg.setRecipient(MimeMessage.RecipientType.TO, new InternetAddress(to));
           msg.setSubject(subject);
           msg.setSentDate(new Date());
           msg.setText(content);
           Transport.send(msg);
           System.out.println("成功发送邮件......");
        }catch(Exception se){
         se.printStackTrace();
        }
        }
    }
    }
    //现在的大部分的邮件服务器都要求有身份验证,所以需要此类实现验证功能
    class MailAuthenticator extends Authenticator{

        private String username = null;
        private String userpasswd = null;

        public MailAuthenticator(){}
        public MailAuthenticator(String username,String userpasswd){
            this.username = username;
            this.userpasswd = userpasswd;
        }
        
        public void setUserName(String username){
            this.username = username;
        }

        public void setPassword(String password){
            this.userpasswd = password;
        }

        public PasswordAuthentication getPasswordAuthentication(){
            return new PasswordAuthentication(username,userpasswd);
        }
    }

      

  3.   

    网上有 down一个  你的邮件域名格式不是有错误