Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JavaMail: How to use different SOCKS5 for different threads?  RSS feed

Alan Wake
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 for bob@localhost to connect
  • second thread: uses SOCKS 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?

    And maybe this is related problem below. Some use from stackoverflow adviced me to use SMTPTransport.connect(Socket socket), but there is a problem like this:
    I'm using JavaMail and I want it to work through proxy for every threads (I have multithreading application). I'm using SMTPTransport.connect(Socket socket) for this.

    Here is socket initialization:

    socket = new Socket();
    socket.connect(new InetSocketAddress(smtpHost, smtpPort));
    Here is SMTPTransport call:

    SMTPTransport transport = null;
    transport = (SMTPTransport) mail.getTransport("smtp");
    And so on. But I this error happens:

    DEBUG: JavaMail version 1.4.4 DEBUG: successfully loaded resource: /META-INF/javamail.default.providers DEBUG: Tables of loaded providers DEBUG: Providers Listed By Class Name: {com.sun.mail.smtp.SMTPSSLTransport=javax.mail.Provider[TRANSPORT,smtps,com.sun.mail.smtp.SMTPSSLTransport,Sun Microsystems, Inc], com.sun.mail.smtp.SMTPTransport=javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc], com.sun.mail.imap.IMAPSSLStore=javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Sun Microsystems, Inc], com.sun.mail.pop3.POP3SSLStore=javax.mail.Provider[STORE,pop3s,com.sun.mail.pop3.POP3SSLStore,Sun Microsystems, Inc], com.sun.mail.imap.IMAPStore=javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Sun Microsystems, Inc], com.sun.mail.pop3.POP3Store=javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Sun Microsystems, Inc]} DEBUG: Providers Listed By Protocol: {imaps=javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Sun Microsystems, Inc], imap=javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Sun Microsystems, Inc], smtps=javax.mail.Provider[TRANSPORT,smtps,com.sun.mail.smtp.SMTPSSLTransport,Sun Microsystems, Inc], pop3=javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Sun Microsystems, Inc], pop3s=javax.mail.Provider[STORE,pop3s,com.sun.mail.pop3.POP3SSLStore,Sun Microsystems, Inc], smtp=javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc]} DEBUG: successfully loaded resource: /META-INF/ DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc] DEBUG SMTP: useEhlo true, useAuth true DEBUG SMTP: useEhlo true, useAuth true DEBUG SMTP: starting protocol to host "", port 465 DEBUG SMTP: exception reading response: Read timed out Exception reading response javax.mail.MessagingException: Exception reading response; nested exception is: Read timed out at com.sun.mail.smtp.SMTPTransport.readServerResponse( at com.sun.mail.smtp.SMTPTransport.openServer( at com.sun.mail.smtp.SMTPTransport.protocolConnect( at javax.mail.Service.connect( at javax.mail.Service.connect( at javax.mail.Service.connect( at com.sun.mail.smtp.SMTPTransport.connect( at at java.util.concurrent.Executors$ at java.util.concurrent.FutureTask$Sync.innerRun( at at java.util.concurrent.ThreadPoolExecutor.runWorker( at java.util.concurrent.ThreadPoolExecutor$ at Caused by: Read timed out at Method) at at at at at at com.sun.mail.util.LineInputStream.readLine( at com.sun.mail.smtp.SMTPTransport.readServerResponse( ... 13 more

    So as I see JavaMail can't read from socket. So what am I doing wrong? If I try to use transport.connect() method without using Socket in constructor all works perfectly and smtpHost/smtpPort are accessible from the telnet and I have no any firewalls/antiviruses.
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!