javax.mail.MessagingException: Could not connect to SMTP host?

后端 未结 4 1480
谎友^
谎友^ 2021-01-02 19:14

following is my code to send mail:

import java.util.Properties;
import javax.mail.Authenticator;
import javax.mail.Message;
import javax.mail.Message.Recipie         


        
相关标签:
4条回答
  • 2021-01-02 19:18

    This is these two lines which was casting me the problem :

    m_properties.put("mail.smtp.socketFactory.port", "465");
      m_properties.put("mail.smtp.socketFactory.class","javax.net.ssl.SSLSocketFactory");
    

    and added this line :

    m_properties.put("mail.smtp.starttls.enable", "true");
    

    After removing and adding the above lines of code it worked fine.

    0 讨论(0)
  • 2021-01-02 19:20

    Try to add port 9000 to your inbound rules in your windows firewall.

    0 讨论(0)
  • 2021-01-02 19:27

    This exception usually occurs when there is no service listening on the port you are trying to connect to.

    Try to connect using putty or telnet. I can bet you will get the same error.

    Verify these things:

    • Host name and port you're trying to connect to,
    • The server is listening correctly, and
    • There's no firewall blocking the connection.
    0 讨论(0)
  • 2021-01-02 19:38

    What causes your problem is right there in the stack trace:

    java.net.ConnectException: Connection refused: connect
    

    do you need a password to connect to the SMTP server? Are you sure you are using the right settings (as in port number)? Are you behind a proxy or a firewall? Can you use those settings in a regular mail program (e.g. Thunderbird) and send mails?

    0 讨论(0)
提交回复
热议问题