1. 程式人生 > >om.sun.mail.util.MailConnectException: Couldn't connect to host, port: localhost, 465; timeout -1;

om.sun.mail.util.MailConnectException: Couldn't connect to host, port: localhost, 465; timeout -1;

 

晚上用java mail實現郵件的傳送功能出現了以下錯誤

com.sun.mail.util.MailConnectException: Couldn't connect to host, port: localhost, 465; timeout -1;
      nested exception is:
    	java.net.ConnectException: failed to connect to localhost/127.0.0.1 (port 465) after 90000ms: isConnected failed: ECONNREFUSED (Connection refused)
        at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:2209)
        at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:740)
        at javax.mail.Service.connect(Service.java:366)
        at javax.mail.Service.connect(Service.java:246)
        at javax.mail.Service.connect(Service.java:267)
        at com.example.fyf.myemail.MainActivity.sendMail(MainActivity.java:193)
        at com.example.fyf.myemail.MainActivity.access$000(MainActivity.java:62)
        at com.example.fyf.myemail.MainActivity$1$1.run(MainActivity.java:96)
        at java.lang.Thread.run(Thread.java:818)

 對比了之前傳送正確的程式碼,原來自己修改了某個引數

 props.setProperty("mail.host",  "smtp.qq.com");

  改成了

 props.setProperty("mail.stmp.host",  "smtp.qq.com");

具體原因自己還沒搞懂,希望大家可以借鑑一下