在jsp中使用javamail(下)2001年02月14日 1546.htm

来自「这是一本关于java的书」· HTM 代码 · 共 402 行 · 第 1/2 页

HTM
402
字号
            src="在JSP中使用JavaMail(下)2001年02月14日 1546.files/white_pixel.gif" 
            width=1></TD></TR></FORM><!------------全文检索部分结束--------></TBODY></TABLE><BR>
      <TABLE cellSpacing=0 cellPadding=0 width=120 bgColor=#666666 border=0>
        <TBODY>
        <TR bgColor=#486cac>
          <TD vAlign=top align=left width=10 height=8><IMG height=1 
            src="在JSP中使用JavaMail(下)2001年02月14日 1546.files/white_pixel.gif" 
            width=1></TD>
          <TD class=index01 vAlign=top width=103 height=8>
            <DIV align=center>相关文章</DIV></TD>
          <TD vAlign=top align=right width=7 height=8><IMG height=1 
            src="在JSP中使用JavaMail(下)2001年02月14日 1546.files/white_pixel.gif" 
            width=1></TD></TR>
        <TR align=left>
          <TD vAlign=top width=10><IMG height=1 
            src="在JSP中使用JavaMail(下)2001年02月14日 1546.files/blank.gif" width=1 
            border=0></TD>
          <TD vAlign=center align=left width=103><IMG height=5 
            src="在JSP中使用JavaMail(下)2001年02月14日 1546.files/blank.gif" width=1 
            border=0><BR><SPAN class=content><IMG height=4 
            src="在JSP中使用JavaMail(下)2001年02月14日 1546.files/white_pixel.gif" 
            width=4>&nbsp;</SPAN> <SPAN class=index01><A 
            href="http://www0.ccidnet.com/tech/web/2001/02/14/58_1671.html"><SPAN 
            class=index01>在JSP中使用JavaMail(上)</SPAN></A></SPAN><BR><SPAN 
            class=content><IMG height=4 
            src="在JSP中使用JavaMail(下)2001年02月14日 1546.files/white_pixel.gif" 
            width=4>&nbsp;</SPAN> <SPAN class=index01><A 
            href="http://www0.ccidnet.com/tech/web/2001/01/15/58_1589.html"><SPAN 
            class=index01>走近JSP</SPAN></A></SPAN><BR><SPAN class=content><IMG 
            height=4 
            src="在JSP中使用JavaMail(下)2001年02月14日 1546.files/white_pixel.gif" 
            width=4>&nbsp;</SPAN> <SPAN class=index01><A 
            href="http://www0.ccidnet.com/tech/web/2000/12/22/58_1513.html"><SPAN 
            class=index01>我认为JSP有问题(上)</SPAN></A></SPAN><BR><SPAN 
            class=content><IMG height=4 
            src="在JSP中使用JavaMail(下)2001年02月14日 1546.files/white_pixel.gif" 
            width=4>&nbsp;</SPAN> <SPAN class=index01><A 
            href="http://www0.ccidnet.com/tech/web/2000/12/22/58_1514.html"><SPAN 
            class=index01>我认为JSP有问题(下)</SPAN></A></SPAN><BR><SPAN 
            class=content><IMG height=4 
            src="在JSP中使用JavaMail(下)2001年02月14日 1546.files/white_pixel.gif" 
            width=4>&nbsp;</SPAN> <SPAN class=index01><A 
            href="http://www0.ccidnet.com/tech/web/2000/12/18/58_1471.html"><SPAN 
            class=index01>实例讲解JSP Model2体系结构(下)</SPAN></A></SPAN><BR><!--------相关内容部分---------></TD>
          <TD vAlign=top width=7><IMG height=1 
            src="在JSP中使用JavaMail(下)2001年02月14日 1546.files/blank.gif" width=1 
            border=0></TD></TR>
        <TR>
          <TD vAlign=bottom align=left width=10 height=2><IMG height=1 
            src="在JSP中使用JavaMail(下)2001年02月14日 1546.files/white_pixel.gif" 
            width=1></TD>
          <TD vAlign=top align=left width=103 height=2><IMG height=1 
            src="在JSP中使用JavaMail(下)2001年02月14日 1546.files/blank.gif" width=1 
            border=0></TD>
          <TD vAlign=bottom align=right width=7 height=2><IMG height=1 
            src="在JSP中使用JavaMail(下)2001年02月14日 1546.files/white_pixel.gif" 
            width=1></TD></TR></TBODY></TABLE><BR><A 
      href="javascript:MM_openBrWindow('http://club.ccidnet.com/remark.php3?channel=Internet开发&amp;title=在JSP中使用JavaMail(下)','','width=360,height=280');void(0);"><IMG 
      height=20 src="在JSP中使用JavaMail(下)2001年02月14日 1546.files/title_02.gif" 
      width=90 border=0></A><BR><A 
      href="http://club.ccidnet.com/bbs.php3?sub_menu_id=1&amp;channel=Internet开发&amp;title=在JSP中使用JavaMail(下)"><IMG 
      height=20 src="在JSP中使用JavaMail(下)2001年02月14日 1546.files/title_03.gif" 
      width=90 border=0></A><BR><A 
      onclick="window.open('/html//send_to_friend_front.php3?sub_chan_id=33&amp;article_id=1672&amp;channel_article_table=t_tech_article&amp;article_content=','','width=640,hight=480,scrollbars=yes')" 
      href="http://www0.ccidnet.com/tech/web/2001/02/14/58_1672.html#"><IMG 
      height=20 src="在JSP中使用JavaMail(下)2001年02月14日 1546.files/title_04.gif" 
      width=90 border=0></A><BR><A href="javascript:self.print()"><IMG height=20 
      src="在JSP中使用JavaMail(下)2001年02月14日 1546.files/title_05.gif" width=90 
      border=0></A><BR><BR>
      <DIV align=center><IMG height=1 
      src="在JSP中使用JavaMail(下)2001年02月14日 1546.files/blank.gif" width=1 
      border=0></DIV>
      <P></P></DIV><BR></TD>
    <TD vAlign=top align=middle colSpan=3>
      <DIV class=Name02 align=center>
      <TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
        <TBODY>
        <TR><!----------页面位置部分----------->
          <TD width=19><IMG height=1 
            src="在JSP中使用JavaMail(下)2001年02月14日 1546.files/blank.gif" width=1 
            border=0></TD>
          <TD class=content width=426><IMG height=10 
            src="在JSP中使用JavaMail(下)2001年02月14日 1546.files/triangle.gif" 
            width=11> &nbsp;当前页面位置: <A style="TEXT-DECORATION: none" 
            href="http://www0.ccidnet.com/"><FONT color=#000000>主页</FONT></A>: 
            <A style="TEXT-DECORATION: none" 
            href="http://www0.ccidnet.com/tech"><FONT 
            color=#000000>技术天地</FONT></A>: <A style="TEXT-DECORATION: none" 
            href="http://www0.ccidnet.com/tech/web"><FONT 
            color=#000000>Internet开发</A>: 技术文章</FONT></TD>
          <TD width=67><IMG height=1 
            src="在JSP中使用JavaMail(下)2001年02月14日 1546.files/blank.gif" width=1 
            border=0></TD><!------------页面位置部分结束-----------></TR></TBODY></TABLE><BR>
      <TABLE cellSpacing=0 cellPadding=0 width="90%" border=0>
        <TBODY>
        <TR vAlign=top>
          <TD><!------------文章内容主体部分---------><SPAN class=name00><FONT 
            color=#ff3300>在JSP中使用JavaMail(下)</FONT><BR></SPAN><SPAN 
            class=Name01><FONT color=#666666>(作者:天译编译 2001年02月14日 
            15:46)</FONT></SPAN><BR><BR><SPAN 
            class=content><STRONG>第二部分:关于JavaMail</STRONG> 
            <BR><STRONG>文档的使用</STRONG> <BR>  下载的JavaMail 
            API中带的文档是很有用的。你可以在JavaMail下的/docs/javadocs/index.html找到它。第二部分主要将分析邮件程序的组件。你可以通过阅读文档来获得更多这方面的信息。 
            <BR><BR>  组件发送邮件需要使用JavaMail,它使对邮件的操作变得简单易用。 
            <BR><BR><STRONG>属性对象</STRONG> 
            <BR>  JavaMail需要创建一个格式为"mail.smtp.host"的文件用来发送信息。 <BR><BR>   
            Properties props = new Properties (); <BR><BR>   
            props.put("mail.smtp.host", "smtp.jspinsider.com"); 
            <BR><BR><STRONG>对话对象</STRONG> <BR>  所有的基于JavaMail的程序都至少需要一个或全部的对话目标。 
            <BR><BR>   Session sendMailSession; <BR><BR>   sendMailSession = 
            Session.getInstance(props, null); <BR><BR><STRONG>传输</STRONG> 
            <BR>  邮件的传输只有送出或受到两种状态。JavaMail将这两种不同状态描述为传输和储存。传输将送出邮件,而储存将收取邮件。 
            <BR><BR>   Transport transport; <BR><BR>   transport = 
            sendMailSession.getTransport("smtp"); 
            <BR><BR>  使用JavaMail能为我们节约大量的时间。JavaMail能代替所有的SMTP的工作。 
            <BR><BR>  注意:JavaMail并不能完全的支持所有的邮件发送收取工作。它目前仅支持IMAP、SMTP和POP3,除此以外你只有等待新的JavaMail版本或自己开发协议。 
            <BR><BR><STRONG>信息对象</STRONG> <BR>  信息对象将把你所发送的邮件真实的反映出来。 <BR><BR>   
            Message newMessage = new MimeMessage(sendMailSession); 
            <BR><BR>  这就是我们所需要的全部四个对象。下一步将是如何将对象加入到JSP中。 <BR><BR>   
            <BR><BR><STRONG>第三部分:JavaMail和JSP的结合</STRONG> 
            <BR><STRONG>创建JSP</STRONG> 
            <BR>  下面我们将开始将他们结合在一起。最重要的一点是要确认根据页面指示分类。还要记得在邮件上标注java.util.date。 
            <BR><BR>   &lt;%@ page <BR><BR>   import= " javax.mail.*, 
            javax.mail.internet.*, javax.activation.*, java.util.*" <BR><BR>   
            %&gt; <BR><BR>  其次,创建邮件发送的确认信息。确认信息可以是任意的,一般常用"你的邮件已经发送出去了(Your mail 
            has been sent)。" <BR><BR><STRONG>信息是如何创建和发送的</STRONG> 
            <BR>  我们在第二部分里已经讨论过信息对象的创建。我们下面将对信息进行操作。这就和设置信息对象的属性一样简单。你可以通过下面的程序来实现这项操作。 
            <BR><BR>   newMessage.setFrom(new 
            InternetAddress(request.getParameter("from"))); <BR><BR>   
            newMessage.setRecipient(Message.RecipientType.TO, new 
            InternetAddress(request.getParameter("to"))); <BR><BR>   
            newMessage.setSubject(request.getParameter("subject")); <BR><BR>   
            newMessage.setSentDate(new Date()); <BR><BR>   
            newMessage.setText(request.getParameter("text")); 
            <BR><BR>  现在将开始发送信息。通过JavaMail来实现它非常简单。 <BR><BR>   
            transport.send(newMessage); <BR><BR><STRONG>将所有的组件结合在一起</STRONG> 
            <BR>  现在所有的组件都已经齐全了。现在将它们都放在JSP里面。要注意每一个错误信息,并将它反馈给用户。代码如下,你可以通过复制它们直接使用: 
            <BR><BR>  Sample JSP email Utility Using JavaMail <BR><BR>  &lt;%@ 
            page <BR><BR>   import=" javax.mail.*, javax.mail.internet.*, 
            javax.activation.*,java.util.*" <BR><BR>   %&gt; 
            <BR><BR>  &lt;html&gt; <BR><BR>  &lt;head&gt; 
            <BR><BR>  &lt;TITLE&gt;JSP meets JavaMail, what a sweet 
            combo.&lt;/TITLE&gt; <BR><BR>  &lt;/HEAD&gt; <BR><BR>  &lt;BODY&gt; 
            <BR><BR>  &lt;% <BR><BR>   try{ <BR><BR>   Properties props = new 
            Properties(); <BR><BR>   Session sendMailSession; <BR><BR>   Store 
            store; <BR><BR>   Transport transport; <BR><BR>   sendMailSession = 
            Session.getInstance(props, null); <BR><BR>   
            props.put("mail.smtp.host", "smtp.jspinsider.com"); <BR><BR>   
            Message newMessage = new MimeMessage(sendMailSession); <BR><BR>   
            newMessage.setFrom(new 
            InternetAddress(request.getParameter("from"))); <BR><BR>   
            newMessage.setRecipient(Message.RecipientType.TO, new 
            InternetAddress(request.getParameter("to"))); <BR><BR>   
            newMessage.setSubject(request.getParameter("subject")); <BR><BR>   
            newMessage.setSentDate(new Date()); <BR><BR>   
            newMessage.setText(request.getParameter("text")); <BR><BR>   
            transport = sendMailSession.getTransport("smtp"); <BR><BR>   
            transport.send(newMessage); <BR><BR>   %&gt; <BR><BR>  &lt;P&gt;Your 
            mail has been sent.&lt;/P&gt; <BR><BR>  &lt;% <BR><BR>   } 
            <BR><BR>   catch(MessagingException m) <BR><BR>   { <BR><BR>   
            out.println(m.toString()); <BR><BR>   } <BR><BR>  %&gt; 
            <BR><BR>  &lt;/BODY&gt; <BR><BR>  &lt;/HTML&gt; 
            <BR><BR>  你会很快体会到JavaMail的方便之处,JSP和JavaMail将是未来的希望。 
            <BR><BR>  &lt;全文完&gt; <BR><BR>&lt;&lt;&lt;&lt;&lt;<A 
            href="http://www.ccidnet.com//tech/web/2001/02/14//58_1671.html">上一页</A><BR></SPAN><BR><!-------------文章内容主体部分结束-----></TD></TR></TBODY></TABLE><BR></DIV></TD>
    <TD width=15 height=12><IMG height=1 
      src="在JSP中使用JavaMail(下)2001年02月14日 1546.files/blank.gif" width=1 
    border=0></TD></TR></TBODY></TABLE>
<TABLE height=55 cellSpacing=0 cellPadding=0 width=760 border=0>
  <TBODY>
  <TR>
    <TD height=16>
      <DIV align=center><MAP name=bottombar><AREA shape=RECT coords=0,0,70,14 
        href="http://www0.ccidnet.com/"><AREA shape=RECT coords=79,0,130,15 
        href="http://www0.ccidnet.com/help/webmap.html"><AREA shape=RECT 
        coords=140,0,190,15 
        href="http://www0.ccidnet.com/help/aboutus.html"><AREA shape=RECT 
        coords=199,0,249,15 
        href="http://www0.ccidnet.com/help/readme.html"><AREA shape=RECT 
        coords=256,0,307,15 href="http://search.ccidnet.com/"><AREA shape=RECT 
        coords=315,0,382,14 
        href="http://www0.ccidnet.com/tech/web/2001/02/14/58_1672.html#"></MAP><IMG 
      height=16 alt=与CCIDNET联系 isMap 
      src="在JSP中使用JavaMail(下)2001年02月14日 1546.files/bottombar.gif" width=383 
      useMap=#bottombar border=0> </DIV></TD></TR>
  <TR>
    <TD>
      <DIV align=center><IMG height=2 
      src="在JSP中使用JavaMail(下)2001年02月14日 1546.files/green_dot.gif" 
      width=400></DIV></TD></TR>
  <TR>
    <TD height=40>
      <DIV align=center><MAP name=copyright><AREA shape=RECT coords=64,1,190,8 
        href="mailto:webmaster@ciw.com.cn"></MAP><IMG height=33 
      alt=webmaster@ciw.com.cn 
      src="在JSP中使用JavaMail(下)2001年02月14日 1546.files/copyright.gif" width=295 
      useMap=#copyright border=0 #copyright></DIV></TD></TR></TBODY></TABLE>
<P><BR></P></BODY></HTML>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?