props.put("mail.smtp.host", "localhost");
是指定smtp 服务器的,,你指定的对吗?localhost是什么啊。
应该是类似:
smtp.163.com
或者用ip.但是指定的ip应该有这个功能。

解决方案 »

  1.   

    如果使用163的信箱发信的话,mail.smtp.host的地址应该是smtp.163.com吧
    我写过一个可以用的,你看看
            try{            Properties Props=new Properties();
                Props.put("mail.smtp.host","192.168.1.5");            Session mailConnection=Session.getInstance(Props,null);
                Address fromAddress=new InternetAddress("\"myname\"<[email protected]>");//this mail address must be true;
                List sendAddr = new ArrayList();
                for (int i = 0; i < argmailContent.getsendTo().size(); i++) {
                    if (((String)argmailContent.getsendTo().get(i)).trim().length() > 0)
                    sendAddr.add(argmailContent.getsendTo().get(i));
                }
                Address[] toAddress = new Address[sendAddr.size()];
                for (int i = 0; i < sendAddr.size(); i++) {
                    toAddress[i] = new InternetAddress((String)sendAddr.get(i));
                }            Message msg=new MimeMessage(mailConnection);
                msg.setFrom(fromAddress);
                msg.setContent(mailContent,"text/html;charset=\"gb2312\"");            msg.setRecipients(Message.RecipientType.TO,toAddress);
                msg.setSubject(mailSubject);
                msg.setSentDate(new Date());
                Transport.send(msg);
            }catch (Exception e){
                e.printStackTrace();
                return 0;
            }
      

  2.   

    同wjmmml(笑着悲伤),
    你的代码其他地方没问题,除props.put("mail.smtp.host", "localhost")
    "localhost"应该是你用的smtp服务器地址,如果是你自己建的设成127.0.0.1,如果还不行,看看你的服务器设置对不对
      

  3.   

    163.com的发信功能要有smtp验证的,要有一个认证类
      

  4.   

    你先把localhost改为127.0.0.1试试一下发送。或者改为其它SMTP,如smtp.163.com,得需要加一个验证类。