论坛首页 入门讨论版 Webwork

javamail发送信件的问题

浏览 183 次
该帖已经被评为新手帖
作者 正文
时间:2008-04-17
代码如下:
Properties props = System.getProperties();
props.setProperty("proxySet", "true");
props.setProperty("socksProxyHost", "xxxxx");
props.setProperty("socksProxyPort", "xx");
props.put("mail.smtp.host", "smtp.126.com");
props.put("mail.smtp.auth", "true");
Session session = Session.getDefaultInstance(props, null);
MimeMessage mimeMsg = new MimeMessage(session);
Multipart mp = new MimeMultipart();
mimeMsg.setSubject("test");
BodyPart bp = new MimeBodyPart();
bp.setContent("test", "text/html;charset=GB2312");
mp.addBodyPart(bp);
mimeMsg.setFrom(new InternetAddress("from"));
mimeMsg.setRecipients(Message.RecipientType.TO, InternetAddress.parse("to"));
mimeMsg.setContent(mp);
mimeMsg.saveChanges();
System.out.println("正在发送邮件....");
Session mailSession = Session.getInstance(props, null);
Transport transport = mailSession.getTransport("smtp");
transport.connect((String) props.get("mail.smtp.host"), username,password);
transport.sendMessage(mimeMsg, mimeMsg.getRecipients(Message.RecipientType.TO));
transport.close();

错误信息:
邮件发送失败!javax.mail.MessagingException: Could not connect to SMTP host: smtp.126.com, port: 25;
nested exception is:
java.net.SocketException: Connection reset

在公网上不设代理发送是成功的,但在公司内网里面设置代理后发送显示这个错误。ping代理服务器是成功的,但是在内网里面直接ping或telnet smtp.126.com均失败。请问怎么解决这个问题?
   
时间:2008-04-17
是不是你们公司的网管把25端口给封了?
   
0 请登录后投票
论坛首页 入门讨论版 Webwork

跳转论坛:
JavaEye推荐