程序如下:<%@ page language="java" import="java.util.*,javax.mail.*,javax.mail.internet.*,javax.activation.*" pageEncoding="UTF-8"%>
<%@ page import="javax.mail.Session" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<%
if(request.getParameter("OK") != null){
String host = "smtp.21cn.com";
String from = "[email protected]";
String to = "[email protected]";
try{
Properties prop = System.getProperties();
prop.put("mail.smtp.host",host);
prop.put("mail.smtp.auth","true");
javax.mail.Session s = javax.mail.Session.getDefaultInstance(prop,null);
MimeMessage message = new MimeMessage(s);
message.setFrom(new InternetAddress(from));
message.addRecipient(Message.RecipientType.TO,new InternetAddress(to));
message.setSubject("Hello JavaMail");
message.setText("welcome to china....");
Transport transport = s.getTransport("smtp");
transport.connect(host,"[email protected]","*********");
transport.send(message,message.getAllRecipients());
transport.close();
}
catch(Exception e){
e.printStackTrace();
}
}
%>
<base href="<%=basePath%>">
<title>My JSP 'MyJsp.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
This is my JSP page. <br>
<FORM name="form" action="MyJsp.jsp" method="post"> <INPUT type="submit" name="ok" value="OK"></FORM>
</body>
</html>
<%@ page import="javax.mail.Session" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<%
if(request.getParameter("OK") != null){
String host = "smtp.21cn.com";
String from = "[email protected]";
String to = "[email protected]";
try{
Properties prop = System.getProperties();
prop.put("mail.smtp.host",host);
prop.put("mail.smtp.auth","true");
javax.mail.Session s = javax.mail.Session.getDefaultInstance(prop,null);
MimeMessage message = new MimeMessage(s);
message.setFrom(new InternetAddress(from));
message.addRecipient(Message.RecipientType.TO,new InternetAddress(to));
message.setSubject("Hello JavaMail");
message.setText("welcome to china....");
Transport transport = s.getTransport("smtp");
transport.connect(host,"[email protected]","*********");
transport.send(message,message.getAllRecipients());
transport.close();
}
catch(Exception e){
e.printStackTrace();
}
}
%>
<base href="<%=basePath%>">
<title>My JSP 'MyJsp.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
This is my JSP page. <br>
<FORM name="form" action="MyJsp.jsp" method="post"> <INPUT type="submit" name="ok" value="OK"></FORM>
</body>
</html>
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货