JavaMail java郵件開發_在Web應用中增加郵件傳送功能
阿新 • • 發佈:2018-12-21
建立一個web專案
在lib下新增兩個jar包,mail.jar和之前寫的JavaMail02.jar
SendMailServlet:
package com.yuming.servlet; import java.io.IOException; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import com.yuming.test.JavaMail02; /** * Servlet implementation class SendMailServlet */ public class SendMailServlet extends HttpServlet { protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doPost(request, response); } protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try { JavaMail02.main(new String[]{}); response.getWriter().print("ok!!!"); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(response.getWriter()); } } }