<%@page contentType="text/html;charset=gb2312"%>
<%@ page import="java.util.*, javax.mail.*, javax.mail.internet.*" %>
<html>
<head>
<title>JavaMail 电子邮件发送系统</title>
</head>
<body>
<%
// 以下变量为用户根据自己的情况设置
String host = "smtp.163.com"; // 发送邮件服务器
String user = "vjame"; // 邮件服务器登录用户名
String password = "******"; // 邮件服务器登录密码
String from = "vjame@163.com"; // 发送人邮件地址
String to = "275581963@qq.com"; // 接受人邮件地址
String subject = "Java Mail Example!"; // 邮件标题
String body = "Java Mail Content!"; // 邮件内容
// 以下为发送程序,用户无需改动
try {
Properties props = new Properties();
props.put("mail.smtp.host", host);
props.put("mail.smtp.auth","true");
Session ssn = Session.getInstance(props, null);
MimeMessage message = new MimeMessage(ssn);
InternetAddress fromAddress = new InternetAddress(from);
message.setFrom(fromAddress);
InternetAddress toAddress = new InternetAddress(to);
message.addRecipient(Message.RecipientType.TO, toAddress);
message.setSubject(subject);
message.setText(body);
Transport transport = ssn.getTransport("smtp");
transport.connect(host, user, password);
transport.sendMessage(message, message.getRecipients(Message.RecipientType.TO));
//transport.send(message);
transport.close();
%><p>你的邮件已发送,请返回。</p><%
} catch(Exception m) {
out.println(m.toString());
}%>
</BODY>
</HTML>