Question Details

No question body available.

Tags

java spring-boot jakarta-mail

Answers (2)

May 18, 2026 Score: 1 Rep: 57 Quality: Low Completeness: 60%

The java.net.SocketException: Connection reset error during SMTP communication usually means the TCP connection was abruptly closed by your local network or a firewall, rather than an issue with Google's servers.

Your Spring Boot application.yml and Java code look perfectly fine. Here is how to fix it:

1. Antivirus / Firewall (Most Common) If you are running this application locally, antivirus software (like Avast, AVG, or McAfee) with an "Email Shield" feature will often intercept and kill outbound SMTP traffic on port 587. Temporarily disable your antivirus shields and try again.

2. ISP Port Blocking Some Internet Service Providers block outgoing traffic on port 587. You can verify this by running telnet smtp.gmail.com 587 in your terminal. If it fails to connect, try switching to a mobile hotspot or a VPN.

3. Regarding App Passwords Yes, you must use a 16-digit Google App Password (which requires 2FA to be enabled on your Google account), not your regular Gmail password. However, an incorrect password usually throws an AuthenticationFailedException. A Connection reset means the connection died before authentication even happened. Focus on your firewall and network first.

May 18, 2026 Score: 1 Rep: 77 Quality: Low Completeness: 50%

It is probably due to SSL/TLS Mismatch. Furthermore, I hope you are using the app password, not your gmail password. Please use the below properties file.

spring:
  mail:
    host: smtp.gmail.com
    port: 587
    username: youremail@gmail.com
    password: yourapp_password

properties: mail: smtp: auth: true starttls: enable: true

connectiontimeout: 5000 timeout: 5000 writetimeout: 5000 ssl: trust: smtp.gmail.com

Also, please Try port 465 (SSL).