jsp与java mail api-web开发--天极网3.htm
来自「JavaMail的应用程序合集 jsp的java 的」· HTM 代码 · 共 579 行 · 第 1/3 页
HTM
579 行
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3c.org/TR/1999/REC-html401-19991224/loose.dtd">
<!-- saved from url=(0038)http://www.yesky.com/2/1608502_2.shtml -->
<HTML lang=zh-CN xmlns="http://www.w3.org/1999/xhtml"><HEAD><TITLE>JSP与Java Mail API-web开发--天极网</TITLE>
<META content="JSP与Java Mail API," name=description>
<META content="JSP与Java Mail API," name=keywords>
<META content="天极网 | 全球中文IT第一门户" name=author>
<META content="天极网 | 全球中文IT第一门户" name=Copyright>
<META http-equiv=Content-Type content="text/html; charset=gb2312">
<META http-equiv=Content-Language content=zh-CN><LINK media=all
href="JSP与Java Mail API-web开发--天极网3.files/y_mobile_content.css" type=text/css
rel=stylesheet>
<SCRIPT src="JSP与Java Mail API-web开发--天极网3.files/showlay.js"></SCRIPT>
<META content="MSHTML 6.00.2900.3199" name=GENERATOR></HEAD>
<BODY><!--页面头部--><!--头部-->
<DIV>
<SCRIPT
src="JSP与Java Mail API-web开发--天极网3.files/kingsoft-kuanban-071105.js"></SCRIPT>
</DIV>
<DIV id=topmenu><A href="http://www.yesky.com/">Yesky首页</A>| <A
href="http://product.yesky.com/">产品报价</A>| <A
href="http://cseek.yesky.com/">行情</A>| <A href="http://mobile.yesky.com/">手机</A>
| <A href="http://digital.yesky.com/">数码</A> | <A
href="http://notebook.yesky.com/">笔记本</A> | <A
href="http://pc.yesky.com/">台式机</A> | <A href="http://diy.yesky.com/">DIY硬件</A>
| <A href="http://oa.yesky.com/">外设</A> | <A href="http://net.yesky.com/">网络</A>
| <A href="http://dh.yesky.com/">数字家庭</A> | <A
href="http://lab.yesky.com/">评测</A> | <A href="http://soft.yesky.com/">软件</A> |
<A href="http://e.yesky.com/">e时代</A> | <A href="http://game.yesky.com/">游戏</A>
| <A href="http://pic.yesky.com/">图片</A> | <A
href="http://desktop.yesky.com/">壁纸</A> | <A href="http://q.yesky.com/">群乐</A> |
<A href="http://my.yesky.com/">社区</A> | <A href="http://blog.yesky.com/">博客</A>
| <A href="http://www.mydown.com/">下载</A></DIV>
<DIV id=topbox>
<DIV class=tleft><A href="http://www.yesky.com/"><IMG alt=天极Yesky_全球中文IT第一门户
src="JSP与Java Mail API-web开发--天极网3.files/logo.gif" border=0></A></DIV>
<DIV class=tad><SPAN id=ad1></SPAN></DIV>
<DIV id=search>
<DIV>
<FORM name=searchform action=http://search.chinabyte.com/search method=get
target=_blank><INPUT id=searchzz onmouseover=this.focus() onfocus=this.select()
name=q><INPUT type=hidden value=GB2312 name=encoding><INPUT type=hidden
value=connect name=dir><INPUT type=hidden value=20002 name=cid><INPUT id=search_btn type=submit value=天极搜索> </FORM></DIV>
<DIV class=tdq>
<DIV class=rightarea><A href="http://bj.yesky.com/">北京</A> <A
href="http://hd.yesky.com/">上海</A> <A href="http://gd.yesky.com/">广州</A> <A
href="http://sz.yesky.com/">深圳</A><BR><A href="http://cd.yesky.com/">成都</A> <A
href="http://cq.yesky.com/">重庆</A> <A href="http://sy.yesky.com/">沈阳</A> <A
href="http://xa.yesky.com/">西安</A> </DIV>
<DIV class=rightarea_right><A
href="http://my.yesky.com/">用户<BR>登录</A></DIV></DIV></DIV>
<DIV class=tright>
<DIV class=box1>
<SCRIPT src="JSP与Java Mail API-web开发--天极网3.files/content_text_ad.js"
type=text/javascript></SCRIPT>
</DIV></DIV></DIV>
<SCRIPT src="JSP与Java Mail API-web开发--天极网3.files/flash.js"
type=text/javascript></SCRIPT>
<!-- Error --><!--导航条-->
<DIV id=location>
<DIV class=loleft>您现在的位置: <A href="http://www.yesky.com/" target=_self>天极网</A>
> <A href="http://dev.yesky.com/" target=_self>开发频道</A> > <A
href="http://dev.yesky.com/web" target=_self>web开发</A> > JSP与Java Mail
API</DIV>
<DIV class=adright><SPAN id=ad2></SPAN></DIV></DIV><!--内容块开始-->
<DIV id=conbox><!--左边开始-->
<DIV id=conleft>
<DIV id=contopla1>
<DIV id=__001>
<DIV class=qkong></DIV>
<DIV class=qw1>全文</DIV>
<DIV class=zkong>
<DIV class=kl></DIV>
<DIV class=bj><A href="http://www.yesky.com/2/1608502_2.shtml#pls"
target=_self>评论</A></DIV>
<DIV class=kr></DIV>
<SCRIPT type=text/javascript>
var titiepic ="#";
if (titiepic!="#")
{
document.write("<div class=\"kl\"></div><div class=\"bj\"><a href=\"#\" target=\"_blank\">图片</a></div><div class=\"kr\"></div>");
}
</SCRIPT>
</DIV></DIV></DIV>
<DIV class=topadbg style="PADDING-BOTTOM: 5px"><SPAN id=ad10></SPAN></DIV><A
name=top></A>
<DIV id=contitle>
<H1>JSP与Java Mail API</H1></DIV>
<DIV id=conauthor><SPAN>2002-04-24 16:14 </SPAN><SPAN>作者: 包路跃 </SPAN><SPAN>出处:
Yesky </SPAN><SPAN>责任编辑:<A title=向本编辑提问
href="http://comments.yesky.com/t//6,324/1608502.shtml" target=_blank></A>
</SPAN></DIV>
<DIV class=topadbg><SPAN id=ad9></SPAN></DIV>
<DIV id=conneirong><SPAN id=ad3></SPAN>
<DIV class=guanggao><SPAN id=contentAdv></SPAN></DIV><BR><B> 如何发送HTML类型的邮件
</B><BR><BR> 在上面的例子中,我们实现了如何发送文本格式的邮件,那么HTML格式的邮件该如何发送呢?那就看看下面的例子吧。<BR> 该例由四个文件组成:<BR> ·form.htm:用来建立邮件信息的表单<BR> ·send.jsp:用来获取表单提交的信息,并调用mymail.mail.HTML.send()方法发送邮件<BR> ·StringDataSource.Java:用户自定义的JavaBean,用来将邮件的Body部分转化为HTML格式<BR> ·HTML.Java:用户自定义的JavaBean,用来发送HTML格式的邮件。在send.jsp文件中提到的mymail.mail.HTML.send()方法就在该JavaBean中定义。
<BR><BR>
<TABLE cellSpacing=0 cellPadding=0 width=600 bgColor=#ffffff border=0>
<TBODY>
<TR>
<TD>form.htm<BR><html><BR><head><BR><meta http-equiv="Content-Type"
content="text/html; charset=gb2312"><BR><title> JavaMail -
发送HTML邮件</title><BR></head><BR><body><BR><table border="0" cellspacing="0"
cellpadding="0"><BR><form method="post"
action="send.jsp"><BR><tr><BR><td>SMTP主机:</td><BR><td><input type="text"
name="smtp"
size="80"></td><BR></tr><BR><tr><BR><td>发信人:</td><BR><td><input
type="text" name="from"
size="80"></td><BR></tr><BR><tr><BR><td>收信人:</td><BR><td><input
type="text" name="to"
size="80"></td><BR></tr><BR><tr><BR><td>抄送人:</td><BR><td><input
type="text" name="cc"
size="80"></td><BR></tr><BR><tr><BR><td>暗送人:</td><BR><td><input
type="text" name="bcc"
size="80"></td><BR></tr><BR><tr><BR><td>主题:</td><BR><td><input type="text"
name="subject" size="80"></td><BR></tr><BR><tr><BR><td
valign="top">内容:</td><BR><td><textarea name="body" rows="5"
cols="80"></textarea></td><BR></tr><BR><tr><BR><td colspan="2"
align="center"><input type="submit"
value="发送"></td><BR></tr><BR></form><BR></table><BR></body><BR></html>
<BR><BR>send.jsp<BR><%<BR>//变量声明<BR>Java.lang.String
smtp,from,to,cc,bcc,subject,body; <BR><BR>//获得用户输入数据<BR>smtp =
request.getParameter("smtp");<BR>from =
request.getParameter("from");<BR>to = request.getParameter("to");<BR>cc =
request.getParameter("cc");<BR>bcc =
request.getParameter("bcc");<BR>subject =
request.getParameter("subject");<BR>if(subject!=null){<BR>subject = new
Java.lang.String(subject.getBytes("iso-8859-1"));<BR>}<BR>body =
request.getParameter("body");<BR>//发送邮件<BR>mymail.mail.HTML.send(smtp,from,to,cc,bcc,subject,body);<BR>%>
<BR><BR>mymail.jaf.StringDataSource.Java<BR>package mymail.jaf;<BR>public
class StringDataSource implements
Javax.activation.DataSource<BR>{<BR>private Java.lang.String
data;<BR> private Java.lang.String type; <BR><BR> public
StringDataSource(Java.lang.String data,Java.lang.String
type){<BR> this.data = data;<BR> this.type = type;<BR> }
<BR><BR> public Java.io.InputStream getInputStream() throws
Java.io.IOException{<BR> return new
Java.io.StringBufferInputStream(data);<BR>} <BR><BR> public
Java.io.OutputStream getOutputStream() throws
Java.io.IOException{<BR> throw new Java.io.IOException("it does not
support this method now!");<BR> } <BR><BR> public Java.lang.String
getContentType(){<BR> return type;<BR>} <BR><BR> public
Java.lang.String getName(){<BR> return " mymail ";<BR>}<BR>}
<BR><BR>mymail.mail.HTML.Java<BR>package mymail.mail;<BR><BR>public final
class HTML<BR>{<BR>public static void send(<BR> Java.lang.String smtp,
/*SMTP主机地址*/<BR> Java.lang.String from,
/*发信人*/<BR> Java.lang.String to, /*收信人*/<BR> Java.lang.String
cc, /*抄送人*/<BR> Java.lang.String
bcc, /*暗送人*/<BR> Java.lang.String subject,
/*主题*/<BR> Java.lang.String body /*内容*/<BR> ) throws
Java.lang.Exception<BR>{<BR> //变量声明<BR> Java.util.Properties
props; //系统属性<BR> Javax.mail.Session
mailSession; //邮件会话对象<BR> Javax.mail.internet.MimeMessage mimeMsg;
//MIME邮件对象 <BR><BR> //设置系统属性<BR> props =
Java.lang.System.getProperties();
//获得系统属性对象<BR> props.put("mail.smtp.host",smtp); //设置SMTP主机
<BR><BR> //获得邮件会话对象<BR> mailSession =
Javax.mail.Session.getDefaultInstance(props,null);
<BR><BR> //创建MIME邮件对象<BR> mimeMsg = new
Javax.mail.internet.MimeMessage(mailSession);
<BR><BR> //设置发信人<BR> mimeMsg.setFrom(new
Javax.mail.internet.InternetAddress(from));
<BR><BR> //设置收信人<BR> if(to!=null)<BR>{
<BR>mimeMsg.setRecipients(Javax.mail.Message.RecipientType.TO,Javax.mail.
internet.InternetAddress.parse(to));<BR> }
<BR><BR> //设置抄送人<BR> if(cc!=null)<BR>{<BR>mimeMsg.setRecipients(Javax.mail.Message.RecipientType.CC,Javax.mail.
internet.InternetAddress.parse(cc));<BR> }
<BR><BR>//设置暗送人<BR>if(bcc!=null)<BR>{
<BR>mimeMsg.setRecipients(Javax.mail.Message.RecipientType.BCC,Javax.mail.
internet.InternetAddress.parse(bcc));<BR> }
<BR><BR> //设置邮件主题<BR> //mimeMsg.setSubject(subject);<BR> mimeMsg.setSubject(subject,"gb2312");
<BR><BR> //设置邮件内容,将邮件body部分转化为HTML格式<BR> mimeMsg.setDataHandler(new
Javax.activation.DataHandler(new mymail.jaf. StringDataSource
(body,"text/html")));
<BR><BR> //发送邮件<BR> Javax.mail.Transport.send(mimeMsg);<BR> }<BR>}
</TD></TR></TBODY></TABLE>
<DIV class=right>共5页。 <A class=page href="http://www.yesky.com/2/1608502.shtml"
target=_self><FONT face=Webdings>9</FONT></A> <A class=page
href="http://www.yesky.com/2/1608502_1.shtml" target=_self><FONT
face=Webdings>7</FONT></A> <A class=page
href="http://www.yesky.com/2/1608502.shtml" target=_self><B>1</B></A> <A
class=page href="http://www.yesky.com/2/1608502_1.shtml"
target=_self><B>2</B></A> <A class=page
href="http://www.yesky.com/2/1608502_2.shtml" target=_self><FONT
color=#666666><B>3</B></FONT></A> <A class=page
href="http://www.yesky.com/2/1608502_3.shtml" target=_self><B>4</B></A> <A
class=page href="http://www.yesky.com/2/1608502_4.shtml"
target=_self><B>5</B></A> <A class=page
href="http://www.yesky.com/2/1608502_3.shtml" target=_self><FONT
face=Webdings>8</FONT></A> <A class=page
href="http://www.yesky.com/2/1608502_4.shtml" target=_self><FONT
face=Webdings>:</FONT></A></DIV></DIV><!--广告代码开始-->
<SCRIPT>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?