日期:2014-05-17  浏览次数:20784 次

servlet发邮件发布出去,相同的代码在class中可以发送
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("UTF-8");
String toname = request.getParameter("toname");
String title = request.getParameter("title");
String comment = request.getParameter("comment");

HttpSession session = request.getSession();
Shezhi shezhi = (Shezhi) session.getAttribute("shezhi");
System.out.print(shezhi.getPassword());//我的邮箱密码
System.out.print(shezhi.getName());//我的邮箱名
System.out.print(shezhi.getType());//“smtp.sina.com”

try {

SimpleEmail email = new SimpleEmail();

email.setHostName(shezhi.getType());
email.setAuthentication(shezhi.getName(), shezhi.getPassword());

email.setCharset("UTF-8");
email.addTo(toname);
email.setFrom(shezhi.getName()+"@163.c0m");
email.setSubject(title);
email.setMsg(comment);
email.send();

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


------解决方案--------------------
"@163.c0m" ==》"@163.com"