Java Reference
In-Depth Information
Discussion
Way back in the old days when the Internet was being invented, most email was composed
using the seven-bit ASCII character set. You couldn't send messages containing characters
from international character sets. Then some enterprising soul got the idea to convert non-
ASCII files into ASCII using a form of encoding known as UUENCODE (the UU is a refer-
ence to UUCP, one of the main transport protocols used for email and file transfer at a time
when Internet access was prohibitively expensive for the masses). But this was pretty cum-
bersome, so eventually the Multimedia Internet Mail Extensions, or MIME, was born. MIME
has grown over the years to support, as its name implies, a variety of multimedia types in ad-
dition to supporting odd characters. MIME typing has become very pervasive due to its use
on the Web. As you probably know, every file that your web browser downloads—and a typ-
ical web page may contain from dozens to hundreds of individual files—is classified by the
web server; this “MIME type” tells the browser how to display the contents of the file.
Normal HTML pages are given a type of text/html . Plain text is, as you might guess,
text/plain . Images have types such as image/gif , image/jpeg , image/png , and so on.
Other types include application/ms-word , application/pdf , audio/au , etc.
Mail attachments are files attached to a mail message. MIME is used to classify attachments
so that they can be deciphered by a mail reader the same way that a browser decodes files it
downloads. Plain text and HTML text are the two most popular, but something called Visual
Basic Script, or VBS, was popularized (along with major weaknesses in the design of a cer-
tain desktop operating system) by several famous viruses.
The point of all this? The JavaMail extension is designed to make it easy for you to send and
receive all normal types of mail, including mail containing MIME-typed data. For example,
if you wish to encode a stream containing audio data, you can do so. And, as importantly for
Java, if you wish to encode a Reader containing characters in an 8- or 16-bit character en-
coding, you can do that, too.
The API makes you specify each separate MIME-encoded portion of your message as a
Part . A Part represents a chunk of data that may need special handling by MIME encoders
when being sent, and MIME decoders (in your email client) when being read. Example 17-5
is an example of sending a text/html attachment along with plain text.
Example 17-5. SendMime.java (partial listing)
public
public class
class SendMime
SendMime {
/** The message recipient. */
protected
protected String message_recip = "spam-magnet@somedomainnamehere.com" ;
Search WWH ::




Custom Search