关于 JavaMail 的问题

05-11-24 bing
总出现这样的错误,如何解决啊,是程序不对还是在设置上有问题

DEBUG SMTP: trying to connect to host "smtp.126.com", port 25

javax.mail.MessagingException: Unknown SMTP host: smtp.126.com;
nested exception is:
java.net.UnknownHostException: smtp.126.com

代码:
Properties prop = new Properties();
prop.put("mail.smtp.host","smtp.126.com");
prop.put("mail.smtp.auth","true");

Session mailSession = Session.getInstance(prop,null);
mailSession.setDebug(true);
MimeMessage message = new MimeMessage(mailSession);

//set message
message.setSubject(mailSubject);
message.setText(mailContent);
message.setSentDate(new Date());

InternetAddress fromAddress = new InternetAddress(x x x@126.com");
InternetAddress recieveAddress = new InternetAddress(strReceiveAddress);
message.setFrom(fromAddress);
message.setRecipient(Message.RecipientType.TO,recieveAddress);


//save the message
message.saveChanges();
//send
Transport transMail=mailSession.getTransport("smtp");

transMail.connect("smtp.126.com","x x x x","x x x x");
transMail.sendMessage(message,message.getAllRecipients());
transMail.close();

banq
2005-11-25 10:17
关键是:net.UnknownHostException: smtp.126.com
是域名无法解析, 防火墙限制,还是126.com对发送者有密码验证 都有可能

猜你喜欢