MailConnectException while sending mail using java mail api

前端 未结 5 813
北恋
北恋 2020-12-12 05:09

Trying to send an email using java mail api. And I keep getting MailConnectException. I have tried multiple ways to solve it without success.

Exception is thrown by

相关标签:
5条回答
  • 2020-12-12 05:43

    For me, de-activating firewall and anti-virus did not work. I tried the alternate ports given in the mailtrap's SMTP settings 25 or 465 or 587 or 2525

    changing spring.mail.port to 2525 in the applications.properties file worked for me

    0 讨论(0)
  • 2020-12-12 05:56
    Session session = Session.getInstance(props, new javax.mail.Authenticator() {
    protected PasswordAuthentication getPasswordAuthentication() {
        return new PasswordAuthentication(username, password);
    }
    });   
    props.put("mail.smtp.port", "587");  transport.send(message);
    
    0 讨论(0)
  • 2020-12-12 06:00

    After 8 hours of pain, I've solved this by turning off:

    1) my windows firewall

    2) my antivirus software

    hope this helps

    0 讨论(0)
  • 2020-12-12 06:04

    I met the same problem, and the reason is that I opened a vpn. Hope this will be helpful.

    0 讨论(0)
  • 2020-12-12 06:05

    This looks like network problem. Even though it could occur due to variety of reasons, like :-

    "Couldn't connect to host, port" could be caused by wrong host name, wrong port, a blocking firewall (on the server, on gateways, even on your own machine), network failure, server downtime, etc.

    Can you connect to the mail server using telnet ?

    Also see this FAQ for some mistakes you committed http://www.oracle.com/technetwork/java/javamail/faq/index.html#commonmistakes

    Read this answer on how to send emails using gmail https://stackoverflow.com/a/47452/3107043

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