Error is self explainatory: javax.mail.MessagingException: Could not connect to SMTP host: localhost, port: 25;
You have no SMTP server on localhost, but you configure it there :
// Assuming you are sending email from localhost String host = "localhost"; ... // Setup mail server properties.setProperty("mail.smtp.host", host);
So you must:
- either configure a local SMTP server as a relay on your local system (Postfix or sendmail are two well knows servers)
- of configure a dummy server that simply traces the mail request but does not even try to deliver mail (Python is known to have such dummy servers out of the box)
- or configure your application with a server that you are allowed to use – contact your system admin in a corporate environment, or your ISP in an individual one. Anyway, you will need that even to configure a true relay.