There are a bunch of properties you need to set correctly in the right combination for proxies to work in JavaMail. And JavaMail only supports anonymous SOCKS proxies.
Simple Java Mail however takes cares of these properties for you and adds authenticated proxy support on top of that. It's open source and still actively developed.
Here's how your code would look with Simple Java Mail:
Mailer mailer = new Mailer(// note: from 5.0.0 on use MailerBuilder instead
new ServerConfig("localhost", thePort, theUser, thePasswordd),
TransportStrategy.SMTP_PLAIN,
new ProxyConfig(proxyHost, proxyPort /*, proxyUser, proxyPassword */)
);
mailer.sendMail(new EmailBuilder()
.from("mytest", "mytest@test.com")
.to("test", "test@test.com")
.subject("This is the subject line")
.textHTML("<h1>This is the actual message</h1>")
.build());
System.out.println("Message sent...");
A lot less code and very expressive.