Java Mail:如何在没有全局系统属性的情况下使用 SOCKS 进行 IMAP 处理?
我有这个问题中描述的问题 JavaMail:如何对不同线程使用不同的 SOCKS5 ?
..但是这个问题没有真正的答案:-(
另外我想从 imap(s) 文件夹中检索邮件,但我不知道如何告诉javaMail使用socks代理而不通过全局系统属性进行设置(sockProxyHost等...) 如果我这样做,并行数据库请求也想使用socks代理,但它们不应该(数据库无法通过socks代理访问)
提前非常感谢您的任何提示。 汉斯
I have the problem described in this question
JavaMail: How to use different SOCKS5 for different threads?
..but there is no really answer to this question :-(
additionally I want to retrieve mails from an imap(s) folder and I don't know how to tell javaMail to use a socks proxy without setting via global system properties. (sockProxyHost and so on...)
If I do so parallel database requests also want to use the socks proxy but they shouldn't (db is not accessible via socks proxy)
Thanks a lot in advance for any hint.
Hans
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我和同事一起解决了这个问题,
使用socks代理你必须执行以下操作..
在mail.jar中你可以找到SocketFetcher类。在此类中,将检查是否通过系统属性设置了会话工厂对象或类名称。我实现了从 SSLSocketFactory 复制我自己的 SocketFactory,并且必须在 javaMail 中操作 SocketFetcher,并且我替换了类文件以从我自己的 SocketFactory 调用 createSocket(host, port) 方法。在那里我使用了代理,
另外我还必须操作 SocketFetcher.createSocket()
...
...您必须检查套接字是否已连接,否则将引发异常,并且将使用不属于您的默认 socketFactory 祝你
好运:-)
I solved it together with a colleague
to use a socks proxy you have to do the following..
inside the mail.jar you can find the SocketFetcher class. within this class it is checked if a session factory object or class name is set via system properties. I implemented my own SocketFactory copying from SSLSocketFactory and I had to manipulate the SocketFetcher inside javaMail and I replaced the class file to call createSocket(host, port) method from my own SocketFactory. And there I used a proxy to
additionally I had to manipulate SocketFetcher.createSocket()
...
...you have to check if the socket is already connected otherwise an exception will be thrown and the default socketFactory will be used which isn't yours
Lots of luck :-)