我也是这样调试过来的,刚才!呵呵transport.sendMessage(msg,msg.getRecipients(Message.RecipientType.TO));

解决方案 »

  1.   

    因为smtp服务器需要认证,你把认证信息添进去就可以了
      

  2.   

    Properties props = new Properties();
    props.put("mail.smtp.auth","true");  //smtp认证 
    Session s = Session.getInstance(props,null);
      

  3.   

    这是本人写的一个Java MailBean,绝对好用!//------------------------------------------------------------------------------
    // Copyright 2002
    //
    // Owner: 吴继勇
    //
    // Class: MailBean
    //------------------------------------------------------------------------------// 邮件发送Bean
    //package at.bean;import at.dao.*;
    import at.pub.*;
    import java.util.*;
    import java.text.SimpleDateFormat;
    import javax.mail.*;
    import javax.mail.internet.*;
    import javax.activation.*;public class MailBean {
       private static MailBean instance;        protected String sHost      = "";   // 发送邮件的SMTP服务器
            protected String sFrom      = "";   // 邮件发送者
            protected String sUserName   = "";   // 发送者的用户名
            protected String sPassword   = "";   // 发送者的用户密码   /**
        * 发送邮件
        *
        */
       public void sendMail( String sTo, String sSubject, String sBody ) {
          try {
                  //Properties props = new Properties();
                  Properties props = System.getProperties();
                  // Setup mail server
                  props.put("mail.smtp.host", sHost);
                  props.put("mail.smtp.auth", "true");
                  // Get session
                  Session session = Session.getDefaultInstance(props);              // watch the mail commands go by to the mail server
                  session.setDebug(false);
                  // Define message
                  MimeMessage message = new MimeMessage( session );
                  message.setFrom( new InternetAddress( sFrom ) );
                  message.addRecipient( Message.RecipientType.TO, new InternetAddress( sTo ) );
                  message.setSubject( sSubject );
                  message.setText( sBody );
                  // Send message
                  message.saveChanges();
                  Transport transport = session.getTransport("smtp");
                  transport.connect( sHost, sUserName, sPassword );
                  transport.sendMessage( message, message.getAllRecipients() );
                  transport.close();
          }
          catch ( Exception e ) {
             LogBean logBean = LogBean.getInstance();
             logBean.outError( sTo + ":" + e.getMessage() );
          }
       }   /**
        * 实例
        */
       public static synchronized MailBean getInstance() {
          if(instance == null)
             instance = new MailBean();
          return instance;
       }   /**
        * 初始化
        */
       private MailBean() {
         // 参数管理器
         ParameterFactory paraFactory = ParameterFactory.getInstance();
         sHost = paraFactory.getMailName( "host" );
         sFrom = paraFactory.getMailName( "from" );
         sUserName = paraFactory.getMailName( "username" );
         sPassword = paraFactory.getMailName( "password" );
       }
    }
      

  4.   

    再附上JSP中调用的方法: MailBean mailBean = MailBean.getInstance();
    mailBean.sendMail( sToMail, sEmailSubject, sEmailBody );