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
    }

    }

  • 相关阅读:
    .NET框架程序设计三个概念:.NET,.NET平台(PlatForm),.NET框架(Framework)
    解决AVI格式的文件不能删除的问题
    加载项目失败的解决办法
    由Codebehind所引发的
    由Duwamish学习web.config的配置
    JDK、JRE、JVM之间的关系
    hadoop等的下载地址
    eclipse代码自动补全
    UML 类图中的几种关系
    fedora 14 的163的yum源
  • 原文地址:https://www.cnblogs.com/gride-glory/p/7989841.html
Copyright © 2011-2022 走看看