在线发邮件例子
环境tomcat4
先要安装JAVAMAILAPI和JavaBeans Activation Framework
然后发送HTML页面如下:
<html>
<head>
<title>Contact Us</title>
<meta http-equiv="Content-Type" content="text/html; charset=big5">
</head><body bgcolor="#FFFFFF" text="#000000" marginwidth="0" marginheight="0" leftmargin="30" topmargin="30"><table width="546" border="1" cellspacing="0" cellpadding="10" height="175" bordercolor="#000000">
  <tr> 
  <form action="/text/send.jsp" name="backinfo" method="post">
    <td height="202">叫禥诀篶鲸е羛蹈セ碞弄ぇ厩獽逼琁︽醇セぇㄆ﹜ 
      <p>厩ネ﹎<input type="text" name="name" size="15"><br>
        <br>
        碞弄厩<input type="text" name="school" size="15"><br>
        <br>
        痁 &nbsp;<input type="text" name="s_class" size="15"><br>
        <br>
        產﹎<input type="text" name="parent" size="15"><br>
        <br>
        ら丁羛蹈筿杠<input type="text" name="phone" size="15"><br>
        <br>
        <center><input type="submit" name="sub" value="send" ></center></p>
    </td>
    </form>
  </tr>
</table>
</body>
</html>发送JSP代码
<%@ page contentType="text/html;charset=Big5" %>
<%@ page import="java.util.*, javax.mail.*" %>
<%@ page import="javax.mail.internet.*" %>
<%@ page import="javax.activation.*" %>
<HTML>
<HEAD>
<TITLE>秎ン祇癳</TITLE>
</HEAD>
<BODY>
<%
String host = "SMTP服务器";
//String to = request.getParameter("to");
String to = "发送目的地址";
//String from = request.getParameter("from");
String from = "发送源地址";
//String subject = request.getParameter("subject");
String subject = "兵";
String name = request.getParameter("name");
String school = request.getParameter("school");
String s_class = request.getParameter("s_class");
String parent = request.getParameter("parent");
String phone = request.getParameter("phone");boolean sessionDebug = false;
Properties props = System.getProperties();
  props.put("mail.host", host);
  props.put("mail.transport.protocol", "smtp");
  props.put("mail.pop.auth","true");
Session mailSession=Session.getDefaultInstance(props,null);
mailSession.setDebug(sessionDebug);
Message msg = new MimeMessage(mailSession);
msg.setFrom(new InternetAddress(from));
InternetAddress[] address = {new InternetAddress(to)};
msg.setRecipients(Message.RecipientType.TO, address);
msg.setSubject(subject);
msg.setSentDate(new Date());
msg.setText("﹎:"+name+"/"+"厩:"+school+"/"+"痁:"+s_class+"/"+"產:"+parent+"/"+"筿杠:"+phone+"/");
Transport transport=mailSession.getTransport("smtp");
transport.connect(host,"邮件用户名","密码");
transport.send(msg);
%>
筿秎ン竒癳Θ!
</BODY>
</HTML>