源程序如下:
String host = "b2b-chain";
      String from = "[email protected]";
      String to = "[email protected]";
      String fileAttachment = "c:\boot.ini";      // Get system properties
      Properties props = System.getProperties();      // Setup mail server
      props.put("mail.smtp.host", host);      // Get session
      Session session = 
         Session.getInstance(props, null);      // Define message
      MimeMessage message = 
         new MimeMessage(session);
      message.setFrom(
         new InternetAddress(from));
      message.addRecipient(
         Message.RecipientType.TO, 
         new InternetAddress(to));
      message.setSubject(
         "Hello JavaMail Attachment");      // create the message part 
      MimeBodyPart messageBodyPart = 
         new MimeBodyPart();      //fill message
      messageBodyPart.setText("Hi");      Multipart multipart = new MimeMultipart();
      multipart.addBodyPart(messageBodyPart);      // Part two is attachment
      messageBodyPart = new MimeBodyPart();
      DataSource source = 
         new FileDataSource(fileAttachment);
      messageBodyPart.setDataHandler(
         new DataHandler(source));
      messageBodyPart.setFileName(fileAttachment);
      multipart.addBodyPart(messageBodyPart);      // Put parts in message
      message.setContent(multipart);      // Send the message
try
{
      Transport.send( message );
}
catch(Exception e)
{
  System.out.println("-----------\n" + e.toString() + "\n-----------");
}

解决方案 »

  1.   

    怎么会有163.com出现。程序没完整吧。你的host指定有问题吧
      

  2.   

    可能你的邮件服务器指定的错误。
    就是用163的,也不是163。com,也是SMTP。163。COM。
    而且现在smtp好象都要认证。
      

  3.   

    163.com!的SMTP是要认证的,
    Session session = Session.getInstance(props,autho);
      

  4.   

    SMTP.163.net 的可以试一试,好象不需要认证,我发成功过。