日期:2014-05-18  浏览次数:20966 次

javamail 发送邮件出错 急急!!!
发送邮件的servlet; 这个是简单的文本发送但是就是有错 发送不成功 请大家看看 说是Transport.send(msg); 
这条语句出错 

public class Send extends HttpServlet { 

public Send() { 
super(); 


public void doPost(HttpServletRequest request, HttpServletResponse response) 
throws ServletException, IOException

response.setContentType("text/html"); 
PrintWriter out = response.getWriter(); 
request.setCharacterEncoding("gb2312"); 
String from = request.getParameter("from"); 
String to = request.getParameter("to"); 
String subject = request.getParameter("subject"); 
String context = request.getParameter("context"); 
System.out.println(from); 
System.out.println(to); 
System.out.println(subject); 
System.out.println(context); 


// 确定要发送的邮件服务器的地址 
String mailserver = "tang-429"; 
// 设置邮件的传输协议 
try { 
Properties prop = System.getProperties(); 
prop.put("mail.smtp.host", "tang-429"); 

// 建立邮件发送的连接 
Session session = Session.getDefaultInstance(prop, null); 
// 创建发送的信息的载体 
Message msg = new MimeMessage(session); 
// 设置相关的邮件属性 
msg.setFrom(new InternetAddress(from)); 
// 点到点的发送 
msg.setRecipient(Message.RecipientType.TO, new InternetAddress(to)); 
msg.setSubject(subject); 
msg.setSentDate(new Date()); 
msg.setText(context); 

Transport.send(msg); 

} catch (Exception e) { 
e.printStackTrace(); 


out.print("发送成功!!!!"); 
out.flush(); 
out.close(); 





报错: 网上查了很久 也改不对 望好心人帮忙  

tangzhiwei@tang-429.com 
shangxinhua@tang-429.com 
你好 
你好 
javax.mail.MessagingException: Exception reading response; 
  nested exception is
java.net.SocketException: Connection reset 
at com.sun.mail.smtp.SMTPTransport.readServerResponse(SMTPTransport.java:1462) 
at com.sun.mail.smtp.SMTPTransport.close(SMTPTransport.java:645) 
at javax.mail.Transport.send0(Transport.java:171) 
at javax.mail.Transport.send(Transport.java:98) 
at cn.edu.hebut.sxh.Send.doPost(Send.java:68) 
at javax.servlet.http.HttpServlet.service(HttpServlet.java:709) 
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802) 
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252) 
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173) 
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213) 
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178) 
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126) 
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105) 
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107) 
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdap