commons-email

package dbc;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.mail.EmailException;
import org.apache.commons.mail.SimpleEmail;

public class SendMail extends HttpServlet {

/**
* Constructor of the object.
*/
public SendMail() {
super();
}
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
}
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doPost(request,response);
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

response.setContentType("text/html;charset=utf-8");
PrintWriter out = response.getWriter();
request.setCharacterEncoding("utf-8");
SimpleEmail email= new SimpleEmail();
email.setHostName("smtp.qq.com");
email.setAuthentication("1103243851","wuyiming980719");
System.out.println("heree");
try{
email.addTo(request.getParameter("to"));//收件人
email.setFrom("1103243851@qq.com");
email.setSubject(request.getParameter("title"));//邮件主题
email.setMsg(request.getParameter("content"));
email.send();
out.print("success");
}catch(EmailException e) {
e.printStackTrace();
out.print("failed");
}
}

/**
* Initialization of the servlet. <br>
*
* @throws ServletException if an error occurs
*/
public void init() throws ServletException {
// Put your code here
}

}

posted on 2017-12-05 22:35  暗影蔽日  阅读(90)  评论(0编辑  收藏  举报

导航