Java Reference
In-Depth Information
style to be sent over the Internet. (A discussion of the MIME Standard is beyond the scope of
this topic.)
The next several method calls fill the message with the needed information. Addresses used by
a MimeMessage are implemented by the InternetAddress class. You will notice that this class
is used for both the sender and recipients. Neither the subject nor the content of the message is
required to successfully transport the message, but let's face it, how exciting would it be with-
out them?
Now that the Message is ready to be sent, all you have to do is ask your default transport
provider to send it for you. The code snippet to accomplish this is simple and looks like this:
That is all there is to sending a simple e-mail using the JavaMail API.
Using JavaMail in a Servlet
Next, let's look at what is necessary to send an e-mail using JavaMail and servlets. For the
servlet example, you'll use an HTML form to submit the mail message and a servlet to parse
and send the submitted message. The HTML form can be found in Listing 8.2.
<title>JavaMail Form</title>
<form action=”http://localhost/djs/servlet/MailServlet” method=”post”>
<table cellspacing=”2” cellpadding=”2” border=”1”>
<input type=”text” name=”to” size=”30” maxlength=”30”>
<input type=”text” name=”from” size=”30” maxlength=”30”>
Search WWH ::

Custom Search