当前位置: 技术问答>java相关
高分请教:可以在局网中跨代理发送email是什么意思?
来源: 互联网 发布时间:2015-09-25
本文导语: javamail的一个例子中这样写: try { mailhost = "wang"; from = "from@wang"; to = "to@wang"; subject = "您好"; content = "可以跨代理"; Properties props = S...
javamail的一个例子中这样写:
try {
mailhost = "wang";
from = "from@wang";
to = "to@wang";
subject = "您好";
content = "可以跨代理";
Properties props = System.getProperties(); //获得系统属性
//设置代理主机的参数
props.put( "http.proxySet", "true" );
props.put( "http.proxyHost", "172.28.2.1" );
props.put( "http.proxyPort", "85");
props.put("mail.smtp.host", mailhost); //设置SMTP主机
//获得邮件会话对象
session = Session.getDefaultInstance(props,null);
。。。。。。
请高手解释一下这段代码实现什么功能,是什么意思?
try {
mailhost = "wang";
from = "from@wang";
to = "to@wang";
subject = "您好";
content = "可以跨代理";
Properties props = System.getProperties(); //获得系统属性
//设置代理主机的参数
props.put( "http.proxySet", "true" );
props.put( "http.proxyHost", "172.28.2.1" );
props.put( "http.proxyPort", "85");
props.put("mail.smtp.host", mailhost); //设置SMTP主机
//获得邮件会话对象
session = Session.getDefaultInstance(props,null);
。。。。。。
请高手解释一下这段代码实现什么功能,是什么意思?
|
跨代理只是一个说法而已。实质上就是指定一个代理连接到外部网络。
你可以为不同的协议指定不同的代理:
Depending on which protocol you are using, here are several options. I have only used them on Sun JVMs and I know that Microsoft JVMs require different properties.
You need to set three system properties: (1) that you are using a proxy server; (2) the host name of the proxy server; and (3) the port you are connecting to the proxy server on. The sets of property names are as follows; you can probably tell which protocol to use each for:
"proxySet"
"proxyHost",
"proxyPort"
"http.proxySet"
"http.proxyHost"
"http.proxyPort"
"https.proxySet"
"https.proxyHost"
"https.proxyPort"
"ftpProxySet"
"ftpProxyHost"
"ftpProxyPort"
"gopherProxySet"
"gopherProxyHost"
"gopherProxyPort"
"socksProxySet"
"socksProxyHost"
"socksProxyPort"
To set the properties for a proxy server using the HTTP protocol, use something like the following:
Properties props = System.getProperties();
props.setProperty("http.proxySet", "true");
props.setProperty("http.proxyHost", "myHost");
props.setProperty("http.proxyPort", "myPort");
Note that both the property names AND values are string values.
Hope this is what you need.
资料来源:
http://forum.java.sun.com/thread.jsp?thread=289519&forum=31&message=1136575
你可以为不同的协议指定不同的代理:
Depending on which protocol you are using, here are several options. I have only used them on Sun JVMs and I know that Microsoft JVMs require different properties.
You need to set three system properties: (1) that you are using a proxy server; (2) the host name of the proxy server; and (3) the port you are connecting to the proxy server on. The sets of property names are as follows; you can probably tell which protocol to use each for:
"proxySet"
"proxyHost",
"proxyPort"
"http.proxySet"
"http.proxyHost"
"http.proxyPort"
"https.proxySet"
"https.proxyHost"
"https.proxyPort"
"ftpProxySet"
"ftpProxyHost"
"ftpProxyPort"
"gopherProxySet"
"gopherProxyHost"
"gopherProxyPort"
"socksProxySet"
"socksProxyHost"
"socksProxyPort"
To set the properties for a proxy server using the HTTP protocol, use something like the following:
Properties props = System.getProperties();
props.setProperty("http.proxySet", "true");
props.setProperty("http.proxyHost", "myHost");
props.setProperty("http.proxyPort", "myPort");
Note that both the property names AND values are string values.
Hope this is what you need.
资料来源:
http://forum.java.sun.com/thread.jsp?thread=289519&forum=31&message=1136575