<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ru">
		<id>http://www.jexp.ru/index.php?action=history&amp;feed=atom&amp;title=Java_Tutorial%2FServlet%2FEmail</id>
		<title>Java Tutorial/Servlet/Email - История изменений</title>
		<link rel="self" type="application/atom+xml" href="http://www.jexp.ru/index.php?action=history&amp;feed=atom&amp;title=Java_Tutorial%2FServlet%2FEmail"/>
		<link rel="alternate" type="text/html" href="http://www.jexp.ru/index.php?title=Java_Tutorial/Servlet/Email&amp;action=history"/>
		<updated>2026-04-21T22:40:44Z</updated>
		<subtitle>История изменений этой страницы в вики</subtitle>
		<generator>MediaWiki 1.30.0</generator>

	<entry>
		<id>http://www.jexp.ru/index.php?title=Java_Tutorial/Servlet/Email&amp;diff=4938&amp;oldid=prev</id>
		<title>Admin: 1 версия</title>
		<link rel="alternate" type="text/html" href="http://www.jexp.ru/index.php?title=Java_Tutorial/Servlet/Email&amp;diff=4938&amp;oldid=prev"/>
				<updated>2010-06-01T05:07:03Z</updated>
		
		<summary type="html">&lt;p&gt;1 версия&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr style=&quot;vertical-align: top;&quot; lang=&quot;ru&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Предыдущая&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Версия 05:07, 1 июня 2010&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; style=&quot;text-align: center;&quot; lang=&quot;ru&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(нет различий)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
		<author><name>Admin</name></author>	</entry>

	<entry>
		<id>http://www.jexp.ru/index.php?title=Java_Tutorial/Servlet/Email&amp;diff=4937&amp;oldid=prev</id>
		<title> в 17:44, 31 мая 2010</title>
		<link rel="alternate" type="text/html" href="http://www.jexp.ru/index.php?title=Java_Tutorial/Servlet/Email&amp;diff=4937&amp;oldid=prev"/>
				<updated>2010-05-31T17:44:27Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Новая страница&lt;/b&gt;&lt;/p&gt;&lt;div&gt;==  Send out Mail in a Servlet ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
JavaMail Servlet&lt;br /&gt;
           ~~~~~~~~~~~~~~~~&lt;br /&gt;
Overview:&lt;br /&gt;
=========&lt;br /&gt;
JavaMailServlet should not be taken as a demo of how to use the Java &lt;br /&gt;
Servlet API. It is rather an example of how the JavaMail APIs could &lt;br /&gt;
be used in a server in a three-tier environment described by the &lt;br /&gt;
following diagram:&lt;br /&gt;
  +-----------+        +-----------+        +-----------+&lt;br /&gt;
  |   IMAP    |        |           |        |           |&lt;br /&gt;
  |  Server   |&amp;lt;-IMAP-&amp;gt;| JavaMail  |&amp;lt;-HTTP-&amp;gt;|    WWW    |&lt;br /&gt;
  +-----------+        | Servlet   |--HTML-&amp;gt;|  Browser  |&lt;br /&gt;
  |   SMTP    |&amp;lt;-SMTP-&amp;gt;|           |        |           |&lt;br /&gt;
  |  Server   |        |           |        |           |&lt;br /&gt;
  +-----------+        +-----------+        +-----------+&lt;br /&gt;
&lt;br /&gt;
The JavaMailServlet supports the following functionality:&lt;br /&gt;
  * login to an IMAP server&lt;br /&gt;
  * list all the messages in the INBOX folder&lt;br /&gt;
  * view the selected message&lt;br /&gt;
  * compose and send a message&lt;br /&gt;
&lt;br /&gt;
Setting up and running the demo:&lt;br /&gt;
================================&lt;br /&gt;
Note: These instructions explain how to compile and run the servlet &lt;br /&gt;
demo with Java Web Server (JWS). The procedure should be similar with &lt;br /&gt;
other web servers that support the Java Servlet API.&lt;br /&gt;
  1. Download the latest version of the Java Web Server from&lt;br /&gt;
     http://www.sun.ru/software/jwebserver/index.html and&lt;br /&gt;
     install according to the included documentation. Make&lt;br /&gt;
     sure JWS is listening to requests on port 80 (you may &lt;br /&gt;
     need to modify it from default port 8080; use the JWS &lt;br /&gt;
     Admin Applet). Make sure you can load the Java Web &lt;br /&gt;
     Server welcome page when you connect with your browser &lt;br /&gt;
     to the machine that the server is installed on. Also,&lt;br /&gt;
     make sure your web browser has cookie support turned on.&lt;br /&gt;
  2. Set your classpath to include the following:&lt;br /&gt;
      * mail.jar:    in the JavaMail API distribution&lt;br /&gt;
      * activation.jar:  in the JAF distribution&lt;br /&gt;
      * jws.jar:    in the /lib/ directory in JWS installation&lt;br /&gt;
  3. In javamail-1.1/demo/servlet directory, compile the &lt;br /&gt;
     JavaMailServlet.java file. That produces two class files,&lt;br /&gt;
     JavaMailServlet.class and MailUserData.class. Copy these&lt;br /&gt;
     class files to the /servlets/ directory in the JWS &lt;br /&gt;
     installation.&lt;br /&gt;
  4. Copy the mail.jar and activation.jar to the /lib/&lt;br /&gt;
     directory in the JWS installation.&lt;br /&gt;
  5. Copy the JavaMail.html file to the /public_html/&lt;br /&gt;
     directory in the JWS installation.&lt;br /&gt;
  6. Restart Java Web Server to pick up the new jar files&lt;br /&gt;
     added to its lib directory. Check again that you can&lt;br /&gt;
     load the default JWS page to verify that the server&lt;br /&gt;
     is working fine.&lt;br /&gt;
  7. Using a web browser, go to &lt;br /&gt;
     http://&amp;lt;hostname&amp;gt;/JavaMail.html and login to a&lt;br /&gt;
     valid IMAP account. From here on, you can view &lt;br /&gt;
     messages in your INBOX and create and send new &lt;br /&gt;
     messages.&lt;br /&gt;
&lt;br /&gt;
JavaMailServlet Design:&lt;br /&gt;
=======================&lt;br /&gt;
The following is a brief description of JavaMailServlet class. It&lt;br /&gt;
is not intended to serve as an example of how to develop servlets;&lt;br /&gt;
see http://java.sun.ru/products/servlet for information on the Java&lt;br /&gt;
Servlet API. You may find it useful to refer to JavaMailServlet.java&lt;br /&gt;
source while reading this.&lt;br /&gt;
The JavaMailServlet uses two primary methods to process all&lt;br /&gt;
requests: doPost() and doGet(). doPost() processes submissions&lt;br /&gt;
from the login and compose forms. When the user logs in, the&lt;br /&gt;
doPost() method gets a JavaMail Session and uses the values&lt;br /&gt;
of the &amp;quot;hostname&amp;quot;, &amp;quot;username&amp;quot; and &amp;quot;password&amp;quot; parameters to login&lt;br /&gt;
to the IMAP Store and get the INBOX Folder. To preserve state&lt;br /&gt;
between multiple HTTP requests, the necessary information&lt;br /&gt;
(Session, Store, Folder, URLName) are collected in the&lt;br /&gt;
MailUserData object which is stored using JWS&amp;quot;s Session&lt;br /&gt;
technology (don&amp;quot;t confuse HttpSession and JavaMail&amp;quot;s Session--&lt;br /&gt;
they are different). Finally, the doPost() method outputs &lt;br /&gt;
a table listing the INBOX and the number of messages in it.&lt;br /&gt;
Clicking on the &amp;quot;INBOX&amp;quot; link calls the doGet() method&lt;br /&gt;
which displays a table of message headers. (See the doGet() &lt;br /&gt;
and displayHeaders() methods.)&lt;br /&gt;
Clicking on a message generates a request to the servlet with&lt;br /&gt;
the message sequence number as a parameter. The doGet() method&lt;br /&gt;
receives the request and calls the displayMessage() method &lt;br /&gt;
passing it the message sequence number to display. The &lt;br /&gt;
displayMessage() method first lists the message headers &lt;br /&gt;
by calling the displayMessageHeaders() utility method. &lt;br /&gt;
For text/plain messages, the message content is then displayed&lt;br /&gt;
as a string wrapped in HTML &amp;lt;pre&amp;gt;...&amp;lt;/pre&amp;gt; tags. For multipart &lt;br /&gt;
messages, each part is passed to the displayPart() method.&lt;br /&gt;
There are two displayPart() methods. The one with signature&lt;br /&gt;
  displayPart(MailUserData mud, int msgNum, Part part, &lt;br /&gt;
        int partNum, HttpServletRequest req, &lt;br /&gt;
        ServletOutputStream out) &lt;br /&gt;
is called from the displayMessage() method for each part. For&lt;br /&gt;
any part with text/plain content type, the content is output&lt;br /&gt;
as a string wrapped in HTML &amp;lt;pre&amp;gt;...&amp;lt;/pre&amp;gt; tags. For other&lt;br /&gt;
content types, a link representing the part is displayed,&lt;br /&gt;
along with the part filename and description, if available.&lt;br /&gt;
Clicking in the part link generates a request to the servlet&lt;br /&gt;
with two parameters: the message sequence number and the&lt;br /&gt;
part number. The doGet() method interprets the parameters and &lt;br /&gt;
invokes the second displayPart() method with the signature &lt;br /&gt;
  displayPart(MailUserData mud, int msgNum,&lt;br /&gt;
              int partNum, ServletOutputStream out, &lt;br /&gt;
        HttpServletResponse res) &lt;br /&gt;
This method retrieves the specified part from the message and&lt;br /&gt;
streams it to the web browser, preceded by the MIME content type &lt;br /&gt;
of this part. For example, if the part has a MIME type image/gif,&lt;br /&gt;
the method will set the servlet response MIME content type to &lt;br /&gt;
&amp;quot;image/gif&amp;quot; and then follow it with the bytes of the actual &lt;br /&gt;
image. This leverages the web browser&amp;quot;s content handling&lt;br /&gt;
ability to display different media types.&lt;br /&gt;
Message composition and sending is very similar to message&lt;br /&gt;
viewing. When the &amp;quot;Compose&amp;quot; link is clicked in the headerlist&lt;br /&gt;
page, the servlet outputs the HTML source for the compose&lt;br /&gt;
form stored in the composeForm variable. The user then fills&lt;br /&gt;
in the destination address, subject, text, and presses&lt;br /&gt;
send. This sends a POST request to the servlet, which &lt;br /&gt;
invokes the doPost() method. doPost() calls the servlet&amp;quot;s &lt;br /&gt;
send() method, which creates a new MimeMessage and fills &lt;br /&gt;
it with data retrieved from the POST request. The message&lt;br /&gt;
is then sent to its destination using the Transport.send()&lt;br /&gt;
static method.&amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;/div&gt;</summary>
			</entry>

	</feed>