Java Reference
In-Depth Information
•
A subject
: A subject is a
String
available through the
getSubject
and
setSubject
methods.
•
Zero or more addresses
: Addresses are
String
s that indicate the recipients of the
message. You can add individual addresses using the
addAddress
method, get an
array of messages using the
getAddresses
method, or remove an address (or all
addresses) using the
removeAddresses
methods.
•
Zero or more named headers
: Headers contain metadata about the message. Each
header is a
String
, accessible by its name, which you also specify using a
String
via
the
getHeader
and
setHeader
methods.
•
Zero or more message parts
: Message parts are instances of
MessagePart
that contain
individual parts of a message. You can add a
MessagePart
instance to a multipart
message using the
addMessagePart
method, obtain an array of the
MessagePart
s in a
message using
getMessageParts
, or remove a
MessagePart
instance from a message
using one of these methods:
removeMessagePart
,
removeMessagePartId
,or
removeMessagePartLocation
.
Of course, you can't access these fields directly; instead, you use the accessor and
mutator methods that the
MultipartMessage
class provides.
While the
MultipartMessage
class encapsulates the notion of an entire message, the
MessagePart
class encapsulates a single attachment to a message. Each part has a unique
name, called the
content ID
. When working with
MessagePart
instances, you frequently
refer to them by this ID, which you can obtain for a specific part by invoking its
getContentID
method. Instances also have four other fields:
•
The message contents
: An array of
byte
s you can fetch with the
getContent
or
getContentAsStream
methods
•
The specified content location of a message part
:A
String
typically containing a
URL you can fetch using the
getContentLocation
method
•
The encoding method used to encode the text in a part
: Determined by the
getEncoding
method
•
The MIME type of the part
: Indicates the type of the part (such as text, a PNG
image, and so on), which you can obtain using the
getMIMEType
method
Because of the part-oriented nature of the
MultipartMessage
class, creating one to
send is more complicated than simply creating a
TextMessage
or
BinaryMessage
instance
and setting its payload. Instead, you follow these steps: