I’ve encountered a similar issue before, and it turned out to be related to how the properties were being set. Make sure you’re using ‘mail.smtp.port’ instead of just ‘smtp.port’ in your properties. Also, double-check that you’re using ‘mail.smtp.starttls.enable=true’ for Gmail’s SMTP.
If that doesn’t work, try explicitly setting the transport protocol:
Another thing to consider is whether you’re creating the Session object correctly. Sometimes, if the properties aren’t applied properly to the Session, it can fall back to default settings.
Lastly, ensure you’re not accidentally overwriting your port setting somewhere else in your code. It’s easy to miss, especially in larger scripts.
I’ve been down this rabbit hole before, mate. The trick that worked for me was using SSL instead of TLS for Gmail. Try setting ‘mail.smtp.socketFactory.port’ to 465 and ‘mail.smtp.socketFactory.class’ to ‘javax.net.ssl.SSLSocketFactory’. Also, make sure ‘mail.smtp.auth’ is set to true.
If that doesn’t do it, check if you’re using the latest version of JavaMail. Older versions can be finicky with Gmail’s security updates.
One last thing - if you’re using app passwords (which you should be), double-check that it’s correctly entered. A typo there can cause all sorts of weird behavior.
Let us know if any of this helps. Debugging SMTP issues can be a real pain in the neck!
hey dave, i’ve had a similar issue. try usin ‘mail.smtp.port’ not ‘smtp.port’ and set ‘mail.smtp.starttls.enable=true’. if that don’t work, set protocol via properties.setProperty(‘mail.transport.protocol’,‘smtp’). hope this helps!