使用jsp发email

<%@ page contentType="text/html:charset=gb2312"%>
<%@ page import=
"javax.mail.*,javax.mail.internet.*,javax.activation.*,java.util.*"%>
<%
try{

Properties props=new Properties();
Session sendsession;
Transport transport;
sendsession=Session.getInstance(props,null);
props.put(
"mail.smtp.host","smtp.163.com");
props.put(
"mail.smtp.auth","true");
sendsession.setDebug(true);
Message message=new MimeMessage(sendsession);
message.setFrom(new InternetAddress(request.getParameter(
"from")));
message.setRecipient(Message.RecipientType.TO,new InternetAddress(request.getParameter(
"to")));
message.setSubject(new String(request.getParameter(
"subject").getBytes("ISO8859_1"),"GBK"));
message.setText(new String(request.getParameter(
"text").getBytes("ISO8859_1"),"GBK"));
message.saveChanges();
transport=sendsession.getTransport(
"smtp");
transport.connect(
"smtp.163.com","username","password");
transport.sendMessage(message,message.getAllRecipients());
transport.close();
%>
ok!
<%
}
catch(MessagingException m)
{
out.println(m.toString());
}
%>

lunzi   2005-06-21 01:02:03 评论:1   阅读:1293   引用:0
太烦琐了 @2005-08-11 19:54:22  dff
都是英语,烦

发表评论>>

署名发表(评论可管理,不必输入下面的姓名)

姓名:

主题:

内容: 最少15个,最长1000个字符

验证码: (如不清楚,请刷新)

Copyright@2004-2010 powered by YuLog