Posted on 2007-01-04 10:42
jmb's blog 阅读(111)
评论(0) 编辑 收藏 引用
<%@ page import="javax.mail.*,javax.mail.event.*,javax.mail.internet.*,java.util.*" %>
<html>
<head><title>Post an simple email</title>
</head>
<body>
<%
Properties props = new Properties();
props.put("mail.smtp.host","smtp.163.com");
props.put("mail.smtp.auth","true");
Authenticator auth = new Authenticator(){public PasswordAuthentication getPasswordAuthentication()
{
String username="userName"; //163邮箱登录帐号
String pwd = "password*"; //登录密码
return new PasswordAuthentication(username,pwd);
}
};
Session s = Session.getDefaultInstance(props,auth);
MimeMessage message = new MimeMessage(s);
InternetAddress from = new InternetAddress("jmbkeyes@163.com");
message.setFrom(from);
InternetAddress to = new InternetAddress("jmbkeyes@hotmail.com");
message.setRecipient(Message.RecipientType.TO,to);
message.setSubject("hello");
message.setText("hello,world!");
Transport.send(message);
%>
</body>
</html>