我看了javamail的DEMO,但还是不明白,请指点呀

解决方案 »

  1.   

    http://www.csdn.net/expert/TopicView.asp?id=92577
      

  2.   

    props.put("mail.smtp.auth", "true"); Transport transport = session.getTransport("smtp");
    transport.connect(host, username, password);
      

  3.   

    skyyoung(路人甲):
    knightmiao(): 我加上了props.put("mail.smtp.auth", "true");  
    Transport transport = session.getTransport("smtp");
    transport.connect(host, username, password);但还是报错呀???Mail: try to send mails...
    username: supershot
    password: abdeda
    javax.mail.SendFailedException: Sending failed;
      nested exception is: 
    javax.mail.AuthenticationFailedException
    java.lang.Throwable(java.lang.String)
    java.lang.Exception(java.lang.String)
    javax.mail.MessagingException(java.lang.String, java.lang.Exception)
    javax.mail.SendFailedException(java.lang.String, java.lang.Exception, javax.mail.Address [], javax.mail.Address [], javax.mail.Address [])
    void javax.mail.Transport.send0(javax.mail.Message, javax.mail.Address [])
    void javax.mail.Transport.send(javax.mail.Message)
    boolean com.eastpro.hkisc.util.HtmlMail.send()
    boolean com.eastpro.hkisc.bizlogic.GBMailBean.sendOneMail(com.eastpro.hkisc.bizlogic.MailDetail)
    void com.eastpro.hkisc.bizlogic.GBMailBean.sendAllMail()
    void com.eastpro.hkisc.bizlogic.GBMailPostMan.run()fail sending to [email protected]
      

  4.   

    AuthenticationFailedException
    证明你的认证错误,检查用户和密码
      

  5.   

    skyyoung(路人甲):
    我检查了N遍,换了N个邮箱,163,263,21cn,sohu,等等,都不行,我写的用户名,密码都是对的呀,我都能进邮箱???
    你们怎么可以呢?你用的是哪个版本的javamail?
      

  6.   

    这个是已经通过的. public void sendMail(){
          String to ="[email protected]";
          String from ="[email protected]";
          String server="smtp.163.net";
          String user="xxx";
          String password="xxxxxxx";
          
          try{
          Properties props=new Properties ();
          props.put("mail.smtp.host",server);
          props.put("mail.smtp.auth","true");
          props.put("mail.bebug","true");      //URLName urlName=new URLName(server);
          //PasswordAuthentication pa=new PasswordAuthentication(user,password);
          Session sendMailSession=Session.getDefaultInstance(props,null);
          sendMailSession.setDebug(true);      //sendMailSession.setPasswordAuthentication (urlName,pa);
          //SMTPTransport transport=new SMTPTransport(sendMailSession,null);
          Transport transport=sendMailSession.getTransport("smtp");
          Message msg = new MimeMessage(sendMailSession);
          msg.setFrom(new InternetAddress(from));
          InternetAddress[] address = {new InternetAddress(to)};
        msg.setRecipients(Message.RecipientType.TO, address);
          msg.setSubject("Java Mail Test");
          msg.setHeader("X-Mailer", "msgsend");
          msg.setSentDate(new Date());
          //msg.setText ("Lalalala......");      MimeBodyPart mbp1 = new MimeBodyPart();
        mbp1.setText("Lalalala.......");     // create the second message part
        MimeBodyPart mbp2 = new MimeBodyPart();            // attach the file to the message
          FileDataSource fds = new FileDataSource("c://msdos.sys");
        mbp2.setDataHandler(new DataHandler(fds));
        mbp2.setFileName(fds.getName());     // create the Multipart and its parts to it
        Multipart mp = new MimeMultipart();
        mp.addBodyPart(mbp1);
        mp.addBodyPart(mbp2);     // add the Multipart to the message
        msg.setContent(mp);      transport.connect (server,user,password);
          //transport.connect ();
          transport.sendMessage(msg,msg.getRecipients(Message.RecipientType.TO));
          }
          catch(Exception ex){
            ex.printStackTrace();
          }
      }
      

  7.   

    wolfsquare(狼平方):这个例子成功了,非常感激呀,我马上给分!!!