1
我做了一個需要發送電子郵件的應用程序。它之前有效,但是當我想今天運行它時,它拋出了一個java.net.UnknownHostException: smtp.outlook.com
。它過去星期五工作,在Outlook配置中做了些改變?未知的SMTP主機:smtp.outlook.com
這是我的代碼:
Properties props = new Properties();
props.put("mail.smtp.auth", "true");
props.put("mail.smpt.host", "smtp.outlook.com");
props.put("mail.smtp.port", "587");
props.put("mail.smtp.starttls.enable", "true");
Session session = Session.getInstance(props, null);
try {
transport = session.getTransport("smtp");
try {
transport.connect("smtp.outlook.com", username, wachtwoord);
} catch (MessagingException ex) {
ex.printStackTrace();
}
} catch (NoSuchProviderException ex) {
ex.printStackTrace();
}
它引發以下錯誤:
javax.mail.MessagingException: Unknown SMTP host: smtp.outlook.com;
nested exception is:
java.net.UnknownHostException: smtp.outlook.com
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1932)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:638)
at javax.mail.Service.connect(Service.java:295)
at javax.mail.Service.connect(Service.java:176)
at retourberichten.VerstuurEmail.SendEmail.VerstuurTest(SendEmail.java:143)
at retourberichten.StartApplicatie.App.main(App.java:46)
Caused by: java.net.UnknownHostException: smtp.outlook.com
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:178)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:391)
at java.net.Socket.connect(Socket.java:579)
at java.net.Socket.connect(Socket.java:528)
at com.sun.mail.util.SocketFetcher.createSocket(SocketFetcher.java:288)
at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:231)
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1900)
... 5 more
java.lang.IllegalStateException: Not connected
任何幫助非常感謝,
謝謝!
如果您在連接到一些你曾經是能夠連接到的第一件事就是一個問題,我會檢查是否還有東西。有些東西可能會像防火牆規則一樣發生變化。服務器是否仍然啓動等嘗試ping(不總是最好的測試)或嘗試telnet到主機和端口,嘗試做一個tracert。總之,確保主機仍然可以訪問。並確保您從應用程序的託管位置執行此操作。 – Fred