发信用smtp
163的有可能是smtp.163.com,也可能不是,俺没有试过
公开的都是25

解决方案 »

  1.   

    一般在发送邮件时需要密码,比如163的信箱进入时都要密码,那么用javmail编程发信时,如何加入密码的有关信息。请多指教!
      

  2.   

    public class SmtpAuthenticator extends Authenticator
    {
          protected PasswordAuthentication getPasswordAuthentication()
          {
            return new PasswordAuthentication
            ("username", "password");
          }
    }
    //////////////////////////// String mailto = req.getParameter("sendto");
            String cc = req.getParameter("cc");
            String bcc = req.getParameter("bcc");
            String subject = req.getParameter("subject");
            String content = req.getParameter("content");
            Properties props = System.getProperties();
            props.put("mail.smtp.auth", "true");
            props.put("mail.smtp.host", "smtp.vip.sina.com");
            if(mailto == null)
               return new MsgInfo(false,"没有输入收件人地址!");
            SmtpAuthenticator sa=new SmtpAuthenticator();
            Session sess = Session.getInstance(props,sa);
            //sess.setDebug(true);
            Message msg = new MimeMessage(sess);
            msg.setFrom(new InternetAddress(fromMail));
             msg.setRecipients(Message.RecipientType.TO,InternetAddress.parse(mailto, false));
            if(cc!=null)
              msg.setRecipients(Message.RecipientType.CC,InternetAddress.parse(cc, false));
            if(bcc!=null)
              msg.setRecipients(Message.RecipientType.BCC,InternetAddress.parse(bcc, false));
            msg.setSubject(subject);
            msg.setSentDate(new Date());
           // create the Multipart and its parts to it
            Multipart mp = new MimeMultipart();
            MimeBodyPart mbp1 = new MimeBodyPart();
            mbp1.setText(content);
            mp.addBodyPart(mbp1);
            for (int i=0;i<myUpload.getFiles().getCount();i++)
             {
                 String fileName = myUpload.getFiles().getFile(i).getFileName();
                 if(fileName.length()==0)
                    continue;
               // System.out.println(fileName+"AAAAAAA");
                byte[] fileData = myUpload.getFiles().getFile(i).getData();
                MimeBodyPart mbp = new MimeBodyPart();
                mbp.setDataHandler(new javax.activation.DataHandler(new MailDataSource(fileData,"application/x-msdownload")));  // InternetHeaders(),fileData);
                mbp.setFileName(new String(fileName.getBytes("GBK"),"ISO-8859-1"));
                mp.addBodyPart(mbp);
             }
            // add the Multipart to the message
    msg.setContent(mp);
            Transport.send(msg);