JavaMail API email

xiaoxiao2021-03-13  157

Entry time: 2004-10-18 21:24:31 Source: Seventh Channel 1: Conditions must be downloaded Sun JavaMail API package, address: http://java.sun.com/products/javamail/ I am using The 1.2 version is added to the ClassPath in ClassPath. This program is very simple. You don't need to consider a lot of layers, because the API helps us do these things, below is a simple email Servlet: (For familiar people, I am afraid it is a simple almost a servlet) import java.io. *; Import javax.servlet. *; Import javax.servlet.http. *; Import sun.net.smtp . *; public class SendMailServlet extends HttpServlet {public static String MAIL_FROM = "from"; public static String MAIL_TO = "to"; public static String MAIL_SUBJECT = "subject"; public static String MAIL_BODY = "body"; public static String MAIL_HOST = "mailhost"; public void doGet (HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {resp.setContentType ( "text / html; charset = gb2312"); PrintWriter out = resp.getWriter (); out.println ( "

"); out.println (" "); Out.Println (" < TD> text: "); out.println ("
Send Mail Server: "); out.println (" "); Out.println ("
from: "); Out.Println (" "); OUT.Println (" "); OUT.Println (" < / TD> "); out.println ("
Subject: <

/ TD> "); out.println ("

); out.println ("