I wrote multithreading application which connects to some email accounts from database per thread.
I know that JavaMail have no any options to use SOCKS5 for connection so I decided to use it via System.setProperty method. But this method sets SOCKS5 for whole application and I need to use one SOCKS5 per thread. I mean:
- first thread: uses SOCKS 192.168.0.1:12345 for bob@localhost to
connect - second thread: uses SOCKS 192.168.0.20:12312 for
alice@localhost to connect - third thread: uses SOCKS 192.168.12.:8080
for andrew@localdomain to connect
and so on. Can you tell me how to do this?
You need to create your own socket using the Proxy you want:
Then use it for the connection:
Edit: The tricky bit is if you need authentication with the SMTP server to send mail. If that’s the case, you have to create a subclass of
javax.mail.Authenticatorand pass it to theSession.getInstance()method:Where the authenticator looks like:
This is all untested, but I believe it’s everything you have to do. It should at least put you on the right path.