急!用Java Mail发信总是失败 props.put("mail.smtp.host", "localhost");是指定smtp 服务器的,,你指定的对吗?localhost是什么啊。应该是类似:smtp.163.com或者用ip.但是指定的ip应该有这个功能。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 如果使用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; } 同wjmmml(笑着悲伤),你的代码其他地方没问题,除props.put("mail.smtp.host", "localhost")"localhost"应该是你用的smtp服务器地址,如果是你自己建的设成127.0.0.1,如果还不行,看看你的服务器设置对不对 163.com的发信功能要有smtp验证的,要有一个认证类 你先把localhost改为127.0.0.1试试一下发送。或者改为其它SMTP,如smtp.163.com,得需要加一个验证类。 swing中JTextArea的读取文本问题 jdk/jre/lib/charsets.pack文件是做什么用的? 抽象类的对象可以调用抽象方法吗 我想请教大家一个问题? 我想问,用java读写excel的问题,应该发在哪个板块儿呀? 怎么获取客户端的MAC地址 ***为了丰富广大程序员的业余生活,特在中国游戏中心成立了社团 [程序员驿站] ,欢迎加入*** 奇怪的问题 不懂的问题还得问 p2p是什么?是不是可以用socket实现? 急!!!!请问如何搜索本局域网内的所有计算机名? 我想光学语法是不够的,那是牛干的事情
我写过一个可以用的,你看看
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;
}
你的代码其他地方没问题,除props.put("mail.smtp.host", "localhost")
"localhost"应该是你用的smtp服务器地址,如果是你自己建的设成127.0.0.1,如果还不行,看看你的服务器设置对不对