javamail怎么设置代理发送邮件?

javamail实现代理发送邮件,总是发送失败。麻烦各位帮忙看看,多谢!
代理设置代码:
          /**
* 获得邮件会话属性
*/
public Properties getProperties() {
Properties p = null;
//普通方式发送邮件
if(!isProxy) {
p = new Properties();
p.put("mail.smtp.host", this.mailServerHost);
p.put("mail.smtp.port", this.mailServerPort);
}
//代理方式方式邮件
if(isProxy) {
p = System.getProperties();
p.setProperty("proxySet", "true");
p.setProperty("mail.smtp.host", this.mailServerHost);
p.setProperty("http.proxyhost", "192.168.1.250");
p.setProperty("http.proxyport", "808");
// p.setProperty("proxySet", "true");
// p.setProperty("mail.stmp.host", map.get("Email_Host").toString());
// p.setProperty("http.proxyhost",map.get("Email_Proxy_Host").toString());
// p.setProperty("http.proxyport",map.get("Email_Proxy_Port").toString());
}
p.put("mail.smtp.auth", validate ? "true" : "false");

return p;
}
通过代理可以上网,但是邮件总是发送失败。错误如下:
javax.mail.MessagingException: Unknown SMTP host: smtp.126.com;
  nested exception is:
java.net.UnknownHostException: smtp.126.com
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1211)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:311)
at javax.mail.Service.connect(Service.java:255)
at javax.mail.Service.connect(Service.java:134)
at javax.mail.Service.connect(Service.java:86)
at com.sun.mail.smtp.SMTPTransport.connect(SMTPTransport.java:144)
at javax.mail.Transport.send0(Transport.java:150)
at javax.mail.Transport.send(Transport.java:80)
多谢!

你可能感兴趣的:(javamail,代理发送邮件)