阿七
级别: 未验证会员
精华:
0
发帖: 909
威望: 0 点
金钱: 2161 RMB
贡献值: 0 点
在线时间:512(小时)
注册时间:2006-03-29
最后登录:2008-08-07
|
JAVAMAIL 例子
http://now.net.cn/support/host/javamail.net P:HmT RD'i(szi? JAVA Mail 发邮件的例子 B3&`/{u -------------------------------------------------------------------------------- H5p&dNO gLPgh%B4 javamail.jsp 内容如下 z]
teQaUZ xy1R_*.F^T <%@page contentType="text/html;charset=gb2312"%> HFrwf{J <%@ page import="java.util.*, javax.mail.*, javax.mail.internet.*" %> $2gZpO| <html> Q96^rjY <head> G^/8lIj <title>JavaMail 电子邮件发送系统</title>
:Z5Twb3h </head> E >lW' <body> |jE0H!j ?mJ&zf|B8 <% ]<IK0 // 以下变量为用户根据自己的情况设置 t bEJyA String smtphost = "smtp.now.net.cn"; // 发送邮件服务器 r5S5;jL%t String user = "yauboo"; // 邮件服务器登录用户名 ct![eWsuB String password = "xxx"; // 邮件服务器登录密码 b;%>?U`>p String from = "yauboo@now.net.cn"; // 发送人邮件地址 TQg~I/ String to = "yauboo@now.net.cn"; // 接受人邮件地址 A
2Rp String subject = "Java Mail Subject!"; // 邮件标题 E|v9khN(]. String body = "Java Mail Body!"; // 邮件内容 n!$zO{P r`GA5
}M ,37\8y?o\ // 以下为发送程序,用户无需改动 GPs// try { /@QPJ~%8Ud Properties props = new Properties(); %29lDd(< props.put("mail.smtp.host", smtphost); |Pj]sh[^Y props.put("mail.smtp.auth","true"); 4(D/~OG-6 Session ssn = Session.getInstance(props, null); GLtd6; V e-Ma8+X\ MimeMessage message = new MimeMessage(ssn); oo2CF!Xy ,zVS}!jRhy InternetAddress fromAddress = new InternetAddress(from); r"xs?P&/$ message.setFrom(fromAddress); ^bG91"0A InternetAddress toAddress = new InternetAddress(to); )wyC8` &- message.addRecipient(Message.RecipientType.TO, toAddress); n5>OZ3 E@ s&7TARd message.setSubject(subject); #G!\
MYfQt message.setText(body); SQs+4YJ $q*hE&x
Qd Transport transport = ssn.getTransport("smtp"); Xb2.t^
]f transport.connect(smtphost, user, password); H[2W(q6 transport.sendMessage(message, message.getRecipients(Message.RecipientType.TO)); GUn$IPOM //transport.send(message); Dgc}T8R transport.close(); 7_ s7); %><p>你的邮件已发送,请返回。</p><% F4PWL|1 } catch(Exception m) { Ubm]V{7 out.println(m.toString()); ]FEDAGu }%> L@"&s#~=3 </BODY> RA1K$D ?A </HTML>
|
|
[楼 主]
|
Posted: 2006-04-05 10:51 |
| |