阿七
级别: 未验证会员
精华:
0
发帖: 909
威望: 0 点
金钱: 2161 RMB
贡献值: 0 点
在线时间:512(小时)
注册时间:2006-03-29
最后登录:2008-08-07
|
JAVAMAIL 例子
http://now.net.cn/support/host/javamail.net yuA+YZ ).l`N&_peM JAVA Mail 发邮件的例子 & cV$`L -------------------------------------------------------------------------------- 8DLj?M>N mMSQW6~j javamail.jsp 内容如下 C(@#I7G (u:^4,Z <%@page contentType="text/html;charset=gb2312"%> JVxGS{Z <%@ page import="java.util.*, javax.mail.*, javax.mail.internet.*" %> }fT5(+ Wo <html> :)=>,XwL8 <head> l\t\DX"s_ <title>JavaMail 电子邮件发送系统</title> F)n^p
T </head> ~4^~w#R <body> [~&yLccN b<bj5m4fz> <% %<]4]h // 以下变量为用户根据自己的情况设置 $s.:H4:I String smtphost = "smtp.now.net.cn"; // 发送邮件服务器 K6d2}!5 String user = "yauboo"; // 邮件服务器登录用户名 4}xw&x String password = "xxx"; // 邮件服务器登录密码 I6-.;)McO String from = "yauboo@now.net.cn"; // 发送人邮件地址 +,|aIF String to = "yauboo@now.net.cn"; // 接受人邮件地址 M)6iYA%$ String subject = "Java Mail Subject!"; // 邮件标题 ic;M=dsh: String body = "Java Mail Body!"; // 邮件内容 fPBJ%SZ @
Cd#\D| KBOp}MEz // 以下为发送程序,用户无需改动 ;1AXu/ try { H5!e/4iz Properties props = new Properties(); 4^(aG7 props.put("mail.smtp.host", smtphost); *hvC0U@3 props.put("mail.smtp.auth","true"); NpLZ
,|H Session ssn = Session.getInstance(props, null);
m"/ o4 ISHzlE
Y MimeMessage message = new MimeMessage(ssn); c]%~X&Tg` %EH{p@nM&- InternetAddress fromAddress = new InternetAddress(from); oH='\M%+ message.setFrom(fromAddress); g^:
&Dh InternetAddress toAddress = new InternetAddress(to); !rsGCw!Pg message.addRecipient(Message.RecipientType.TO, toAddress); `nrw[M? %zz,qs)Eu message.setSubject(subject); eXQLE]L] message.setText(body); ("KtJ 6UKZ0~R Transport transport = ssn.getTransport("smtp"); }0V aZ<j transport.connect(smtphost, user, password); #w@V!o transport.sendMessage(message, message.getRecipients(Message.RecipientType.TO)); ,GF]+nI89 //transport.send(message); es^@C9qt transport.close(); FrC)2wX %><p>你的邮件已发送,请返回。</p><% wZfY~ } catch(Exception m) { 7epil out.println(m.toString()); bae;2| w }%> qV0GpVJZU? </BODY> MY}/h@ </HTML>
|
|
[楼 主]
|
Posted: 2006-04-05 10:51 |
| |