• 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
    }

    }

  • 相关阅读:
    做的一个HTML表白页面
    C语言--乱写C语言
    算法学习-带分数
    算法学习--兰顿蚂蚁
    算法学习---一个博弈问题
    数据结构学习--稀疏矩阵的三元组表示
    【Java初探外篇02】——关于静态方法与实例方法
    【Java初探实例篇01】——Java语言基础
    【教程知识向】——关于环境变量以及配置
    【java初探外篇01】——关于Java修饰符
  • 原文地址:https://www.cnblogs.com/gride-glory/p/7989841.html
Copyright © 2020-2023  润新知