關於 JavaMail 的問題

bing發表於2005-11-24
總出現這樣的錯誤,如何解決啊,是程式不對還是在設定上有問題

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();

相關文章