JAVA邮件

今天下载别人BLOG 改时突然看见了
1个名为javamail.jsp的文件
我对JAVAMAIL还比较陌生 帖上来做个笔记吧。
<%@page contentType="text/html;charset=gb2312"%><%@ page import="java.util.*, javax.mail.*, javax.mail.internet.*" %><%
request.setCharacterEncoding("UTF-8");
response.setHeader("Pragma","No-cache"); 
response.setHeader("Cache-Control","no-cache"); 
response.setDateHeader("Expires",0);
String smtphost = "smtp.163.com"; // 发送邮件服务器
String user = ""; // 邮件服务器登录用户名
String password = ""; // 邮件服务器登录密码
String from = ""; // 发送人邮件地址
String to = ""; // 接受人邮件地址 
String subject =request.getParameter("action"); // 邮件标题
String body =new String(request.getParameter("body").getBytes("iso-8859-1"),"UTF-8"); // 邮件内容
// 以下为发送程序,用户无需改动
try {
Properties props = new Properties();
props.put("mail.smtp.host", smtphost);
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(smtphost, user, password);
transport.sendMessage(message, message.getRecipients(Message.RecipientType.TO));
//transport.send(message);
transport.close();
} catch(Exception m) {}%>

你可能感兴趣的:(java,html,jsp,cache,Blog)