java - 通过代理使用 Javamail

标签 java email proxy jakarta-mail socketfactory

我有一个 Java 应用程序,它使用 Javamail (v.1.5.4) 将邮件发送到 POP/SMTP 邮件服务器并进行审阅。该应用程序必须在我们的公司网络中运行,我们有一个代理(f*ck!)来阻止我的请求。我用谷歌搜索了可能的解决方案,Javamail 说我们可以使用 SOCKS5:

Q: How do I configure JavaMail to work through my proxy server? [updated!]

A: JavaMail does not currently support accessing mail servers through a web proxy server. One of the major reasons for using a proxy server is to allow HTTP requests from within a corporate network to pass through a corporate firewall. The firewall will typically block most access to the Internet, but will allow requests from the proxy server to pass through. In addition, a mail server inside the corporate network will perform a similar function for email, accepting messages via SMTP and forwarding them to their ultimate destination on the Internet, and accepting incoming messages and sending them to the appropriate internal mail server.

该解决方案对我无效,因此我必须寻找新的替代方案。有人说他们实现了自定义 SocketFactory,但我不确定这是否足够。有人尝试过吗?

另一个可能的解决方案是使用另一个库,但我没有找到任何可以避免此代理的东西。

有人解决这个问题吗?怎么解决呢?

摘要

问题:我必须在 Java 应用程序中发送和阅读电子邮件,但我的代理阻止了请求。

我尝试过什么?使用javamail,我尝试过使用SOCKS5解决方案,但没有效果。

我在寻找什么?避免此代理的方法。有人讲述了一个自定义的 SocketFactory(但我不确定这是否有效)。我没有找到 Javamail 的任何替代方案。

问候!!

最佳答案

实际上JavaMail确实支持SOCKS代理,只是不支持经过身份验证的代理。

That solution is not valid for me

但你没有解释原因。

还有另一种使用 SOCKS 代理(甚至是经过身份验证的代理)配置 Java Mail 的方法,该方法不涉及配置您自己的套接字工厂。有一个名为 Simple Java Mail 的开源库(完全公开:我维护它),使用起来非常简单:

new Mailer(
        new ServerConfig("smtp.host.com", 587, "user@host.com", "password"),
        TransportStrategy.SMTP_TLS,
        new ProxyConfig("socksproxy.host.com", 1080, "proxy user", "proxy password")
).sendMail(email);

但是,如果您的代理实际上是 HTTP 代理,那么您就不走运了,您将需要求助于类似 Corkscrew 的东西。或connect .

关于java - 通过代理使用 Javamail,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32755870/

相关文章:

java - JAVA 应用程序运行时的连接更改

email - Outlook 中电子邮件的简短预览显示图像 src 而不是替代文本

php - 为什么我收到 Swift_TransportException : Unable to connect with TLS encryption in Server?

php - 如何使用php从特定电子邮件地址获取邮件信息并将标题信息存储到mysql数据库中

emacs - 让 Emacs 通过 Socks 代理访问 HTTPS

java - 我如何访问我从另一个类返回的嵌套 HashMap 值? java

java - 计算图像中的对象数量

proxy - 将经过身份验证的代理服务器与 puppeteer 一起使用

java - 如何返回对象数组的值

java - 在代理服务器中建立 HTTPS 连接时出现问题。(CONNECT 方法)