I have this SMTP server that I'm trying to get into. Now I had the code working this morning and I haven't changed it! And Now I'm getting this error...
javax.mail.SendFailedException: Sending failed; nested exception is: class javax.mail.MessagingException: Could not connect to SMTP host: localhost, port: 25; nested exception is: java.net.ConnectException: Connection refused: connect
Why does it say localhost when in the code I'm giving it the mail server's address?
Pressuming you have checked carefully that no one has changed the mail.smtp.host entry in the Properties you use to get the Session (and no one has) then this is odd. You can enable SMTP debugging (see the docs) to get a better view of what JavaMail is up to. Other than that you can check that you are not remapping the host URL somewhere else (on Windows in %WINDOWS%\System32\drivers\etc\hosts for example). You might also be using an IP address for your host on a network where IP addresses are dynamic. I don't know if JavaMail defaults to localhost, but it might.