这是返回的异常信息:
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 limi
[email protected]: 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 limi
[email protected]        at javax.mail.Transport.send0(Transport.java:218)
        at javax.mail.Transport.send(Transport.java:80)
        at javamail.SendJavaMail.main(SendJavaMail.java:36)
Press any key to continue...

解决方案 »

  1.   

    import java.net.InetAddress;
    import java.net.UnknownHostException;
    import java.util.Date;
    import java.util.Properties;import javax.mail.Message;
    import javax.mail.MessagingException;
    import javax.mail.Session;
    import javax.mail.Transport;
    import javax.mail.internet.InternetAddress;
    import javax.mail.internet.MimeMessage;
    public class B2BMail {
    public void SendMail( String strMailFrom, String strMailTo, String strMailSubject,
                                  String strMailBody, String strMailErrorsTo
                                  ) throws B2BBusinessException {

               String host_name = "";
    try {
    host_name = InetAddress.getLocalHost().getHostAddress();
    } catch( UnknownHostException e ) {
    throw new B2BBusinessException( B2BMessage.getMessage(2018) );
    }

    Properties props = System.getProperties();
    props.put( "mail.smtp.host", host_name );
    props.put( "mail.smtp.from", strMailErrorsTo );

    Session session = Session.getDefaultInstance( props, null );
    try{
    MimeMessage msg = new MimeMessage(session);
    InternetAddress from_adr =  new InternetAddress( strMailFrom );
    msg.setFrom( from_adr );
    InternetAddress to_adr[] = InternetAddress.parse( strMailTo );
    msg.setRecipients( Message.RecipientType.TO, to_adr );
    msg.setSubject( strMailSubject, "iso-2022-jp" );
    msg.setSentDate( new Date() );
    msg.setText( strMailBody, "iso-2022-jp" );
        

    Transport.send( msg );
    }catch ( MessagingException e ) {
    throw new B2BBusinessException( B2BMessage.getMessage(2017) + e.getMessage() );
    }catch ( Exception e ) {
    throw new B2BBusinessException( B2BMessage.getMessage(2017) + e.getMessage() );
    }
    }
    }
      

  2.   

    认证问题,你需要一个传密码认证的类
    需要认证的邮件这句话是不够的:transport.connect("smtp.tom.com","******","******");
    认证的类是继承自javax,mail包中的一个类,类名我忘了,你自己搜索一下,满街都是!