常州五颜六色网络技术有限公司 -> 网站建设 -> JAVAMAIL 例子 登录 -> 注册 -> 回复主题 -> 发表主题

阿七 2006-04-05 10:51
http://now.net.cn/support/host/javamail.net WqS$C;]%  
/8u}VYE  
JAVA Mail 发邮件的例子 cEn|Q  
-------------------------------------------------------------------------------- +:Nz_l  
LoOw]@>  
javamail.jsp 内容如下 i2-]Xl  
`-Tb=o}.  
<%@page contentType="text/html;charset=gb2312"%> CYsLyk  
<%@ page import="java.util.*, javax.mail.*, javax.mail.internet.*" %> y-S23B(  
<html> 0g Hd{H=  
<head> D( y c  
<title>JavaMail 电子邮件发送系统</title> o=PW)37>  
</head> /g8nT1k  
<body> o)Px d  
^)'D eP/  
<% ScQ9p379  
// 以下变量为用户根据自己的情况设置 E 0OHl  
String smtphost = "smtp.now.net.cn"; // 发送邮件服务器 m63>P4h?  
String user = "yauboo"; // 邮件服务器登录用户名 G @]n(\7Y  
String password = "xxx"; // 邮件服务器登录密码 ]ki) (Bb  
String from = "yauboo@now.net.cn"; // 发送人邮件地址 2Ky|+s[`[  
String to = "yauboo@now.net.cn"; // 接受人邮件地址 =B`=f,,#3  
String subject = "Java Mail Subject!"; // 邮件标题 '5A&c(  
String body = "Java Mail Body!"; // 邮件内容 sp_19u  
z~i>GN_  
\5a;_N[Ed  
// 以下为发送程序,用户无需改动 Fr<tk^~/  
try { 'b6qEU#  
Properties props = new Properties(); .3>q3sS  
props.put("mail.smtp.host", smtphost); ] pv!Ll  
props.put("mail.smtp.auth","true"); !u/c'ZLZ>  
Session ssn = Session.getInstance(props, null); tiR i_  
kLXa1^Lq  
MimeMessage message = new MimeMessage(ssn); e5w0}/yW/  
=(bTS n  
InternetAddress fromAddress = new InternetAddress(from); 76u\# {5  
message.setFrom(fromAddress); cK IA.c}N  
InternetAddress toAddress = new InternetAddress(to); er@.<Dc  
message.addRecipient(Message.RecipientType.TO, toAddress); $dKo}  
7{VN27Fa_  
message.setSubject(subject); M(ie1Ju  
message.setText(body); n8q%>.i7  
rT;_"y}  
Transport transport = ssn.getTransport("smtp"); }kJ9< h,  
transport.connect(smtphost, user, password); qg*xdefQ%  
transport.sendMessage(message, message.getRecipients(Message.RecipientType.TO)); bE jQMlb  
//transport.send(message); iE]^ 6i  
transport.close(); )X6I #q8  
%><p>你的邮件已发送,请返回。</p><% L f;Uv[^c  
} catch(Exception m) { jk])S~xl?  
out.println(m.toString()); JP]-a!5Ru  
}%> aOEW$%  
</BODY> +1eb@b X  
</HTML>


查看完整版本: [-- JAVAMAIL 例子 --] [-- top --]



Copyright © 2005-2014 5y6s Inc. 苏ICP备05001866号 Powered by PHPWind 5.0.1
Time 0.010920 second(s),query:5 Gzip enabled