zoukankan      html  css  js  c++  java
  • 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
    }

    }

  • 相关阅读:
    Java笔记(十六)……内部类
    pmm系列~基础函数
    redis基础篇~性能问题
    redis基础篇~big-key
    mysql基础~经典题目二
    (转)STORM启动与部署TOPOLOGY
    (转)项目经理怎么当
    专注力的一点体会
    163源报错Hash Sum mismatch 解决方法
    mapreduce.framework.name
  • 原文地址:https://www.cnblogs.com/gride-glory/p/7989841.html
Copyright © 2011-2022 走看看