通过代理从Java发送电子邮件 [英] Send an email from java through proxy

查看:391
本文介绍了通过代理从Java发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用Java Mail API发送和接收电子邮件. 现在我正在做这个项目的地方有一个代理服务器.

I have used Java Mail API to send emails and receive them. Now the place i am doing this project has a proxy server.

我可以知道如何通过代理服务器从Java发送电子邮件吗?

May i know how to send an email from java through a proxy server?

推荐答案

在此处查看常见问题解答.

JavaMail当前不支持通过Web代理服务器访问邮件服务器.使用代理服务器的主要原因之一是允许来自公司网络内的HTTP请求通过公司防火墙.防火墙通常会阻止大多数对Internet的访问,但会允许来自代理服务器的请求通过.此外,公司网络内部的邮件服务器将执行类似的电子邮件功能,通过SMTP接收邮件并将其转发到Internet上的最终目的地,并接受传入邮件并将其发送到适当的内部邮件服务器.

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.

如果您的代理服务器支持SOCKS V4或V5协议( http://www.socks .nec.com/aboutsocks.html RFC1928 ),并允许匿名连接,您可以告诉Java运行时将所有TCP套接字连接定向到SOCKS服务器.有关socksProxyHost和socksProxyPort属性的最新文档,请参见网络属性指南.这些是系统级属性,而不是JavaMail会话属性.可以在调用应用程序时从命令行设置它们,例如:java -DsocksProxyHost=myproxy ....此功能可用于将SMTP,IMAP和POP3通信从JavaMail定向到SOCKS代理服务器.请注意,设置这些属性会将所有TCP套接字定向到SOCKS代理,这可能会对应用程序的其他方面产生负面影响.

If your proxy server supports the SOCKS V4 or V5 protocol (http://www.socks.nec.com/aboutsocks.html, RFC1928) and allows anonymous connections, you can tell the Java runtime to direct all TCP socket connections to the SOCKS server. See the Networking Properties guide for the latest documentation of the socksProxyHost and socksProxyPort properties. These are system-level properties, not JavaMail session properties. They can be set from the command line when the application is invoked, for example: java -DsocksProxyHost=myproxy .... This facility can be used to direct the SMTP, IMAP, and POP3 communication from JavaMail to the SOCKS proxy server. Note that setting these properties directs all TCP sockets to the SOCKS proxy, which may have negative impact on other aspects of your application.

如果没有这样的SOCKS服务器,如果要使用JavaMail直接访问防火墙外部的邮件服务器,则需要将防火墙配置为允许这种访问. JavaMail不支持通过HTTP代理Web服务器进行访问.

Without such a SOCKS server, if you want to use JavaMail to directly access mail servers outside the firewall, the firewall will need to be configured to allow such access. JavaMail does not support access through a HTTP proxy web server.

这篇关于通过代理从Java发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆