Message implements the Part interface. Message contains a set of attributes and a "content". Messages within a folder also have a set of flags that describe its state within the folder.
Message defines some new attributes in addition to those defined
in the Part interface. These attributes specify meta-data
for the message - i.e., addressing and descriptive information about
the message.
Message objects are obtained either from a Folder or by constructing a new Message object of the appropriate subclass. Messages that have been received are normally retrieved from a folder named "INBOX".
A Message object obtained from a folder is just a lightweight
reference to the actual message. The Message is 'lazily' filled
up (on demand) when each item is requested from the message. Note
that certain folder implementations may return Message objects that
are pre-filled with certain user-specified items.
To send a message, an appropriate subclass of Message (e.g.,
MimeMessage) is instantiated, the attributes and content are
filled in, and the message is sent using the Transport.send
method.
jakarta.mail.Part
| Modifier and Type | Class and Description |
|---|---|
| public static class | Message.
This inner class defines the types of recipients allowed by the Message class. |
| Modifier and Type | Field and Description |
|---|---|
| protected boolean | expunged
True if this message has been expunged. |
| protected Folder | folder
The containing folder, if this message is obtained from a folder |
| protected int | msgnum
The number of this message within its folder, or zero if the message was not retrieved from a folder. |
| protected Session | session
The Session object for this Message |
| Access | Constructor and Description |
|---|---|
| protected | |
| protected | |
| protected |
| Modifier and Type | Method and Description |
|---|---|
| public abstract void | |
| public void | addRecipient(Message.
the recipient type type,the address address)Add this recipient address to the existing ones of the given type. |
| public abstract void | addRecipients(Message.
the recipient type type,the addresses addresses)Add these recipient addresses to the existing ones of the given type. |
| public Address[] | |
| public abstract Flags | Returns: Flags object containing the flags for this messageReturns a |
| public Folder | |
| public abstract Address[] | |
| public int | |
| public abstract Date | |
| public abstract Address[] | Returns: array of Address objectsthe recipient type typeGet all the recipient addresses of the given type. |
| public Address[] | Returns: addresses to which replies should be directedGet the addresses to which replies should be directed. |
| public abstract Date | |
| public Session | |
| public abstract String | |
| public boolean | |
| public boolean | |
| public boolean | Returns: true if the Message matches this search criterion, false otherwise.the Search criterion term)Apply the specified Search criterion to this message. |
| public abstract Message | Returns: the reply Messagereply should be sent to all recipients
of this message replyToAll)Get a new Message suitable for a reply to this message. |
| public abstract void | saveChanges()
Save any changes made to this message into the message-store when the containing folder is closed, if the message is contained in a folder. |
| protected void | |
| public void | |
| public abstract void | |
| public abstract void | |
| public abstract void | |
| protected void | |
| public void | setRecipient(Message.
the recipient type type,the address address)Set the recipient address. |
| public abstract void | setRecipients(Message.
the recipient type type,the addresses addresses)Set the recipient addresses. |
| public void | setReplyTo(Address[]
addresses to which replies should be directed addresses)Set the addresses to which replies should be directed. |
| public abstract void | |
| public abstract void |
| expunged | back to summary |
|---|---|
| protected boolean expunged True if this message has been expunged. | |
| folder | back to summary |
|---|---|
| protected Folder folder The containing folder, if this message is obtained from a folder | |
| msgnum | back to summary |
|---|---|
| protected int msgnum The number of this message within its folder, or zero if the message was not retrieved from a folder. | |
| session | back to summary |
|---|---|
| protected Session session The Session object for this Message | |
| Message | back to summary |
|---|---|
| protected Message() No-arg version of the constructor. | |
| Message | back to summary |
|---|---|
| protected Message(Folder folder, int msgnum) Constructor that takes a Folder and a message number. Used by Folder implementations.
| |
| Message | back to summary |
|---|---|
| protected Message(Session session) Constructor that takes a Session. Used for client created Message objects.
| |
| addFrom | back to summary |
|---|---|
| public abstract void addFrom(Address[] addresses) throws MessagingException Add these addresses to the existing "From" attribute
| |
| addRecipient | back to summary |
|---|---|
| public void addRecipient(Message. Add this recipient address to the existing ones of the given type.
The default implementation uses the
| |
| addRecipients | back to summary |
|---|---|
| public abstract void addRecipients(Message. Add these recipient addresses to the existing ones of the given type.
| |
| getAllRecipients | back to summary |
|---|---|
| public Address[] getAllRecipients() throws MessagingException Get all the recipient addresses for the message.
The default implementation extracts the TO, CC, and BCC
recipients using the
This method returns
| |
| getFlags | back to summary |
|---|---|
| public abstract Flags getFlags() throws MessagingException Returns a
Modifying any of the flags in this returned Flags object will
not affect the flags of this message. Use
| |
| getFolder | back to summary |
|---|---|
| public Folder getFolder() Get the folder from which this message was obtained. If this is a new message or nested message, this method returns null.
| |
| getFrom | back to summary |
|---|---|
| public abstract Address[] getFrom() throws MessagingException Returns the "From" attribute. The "From" attribute contains the identity of the person(s) who wished this message to be sent. In certain implementations, this may be different from the entity that actually sent the message.
This method returns
| |
| getMessageNumber | back to summary |
|---|---|
| public int getMessageNumber() Get the Message number for this Message. A Message object's message number is the relative position of this Message in its Folder. Note that the message number for a particular Message can change during a session if other messages in the Folder are deleted and expunged. Valid message numbers start at 1. Messages that do not belong to any folder (like newly composed or derived messages) have 0 as their message number.
| |
| getReceivedDate | back to summary |
|---|---|
| public abstract Date getReceivedDate() throws MessagingException Get the date this message was received.
| |
| getRecipients | back to summary |
|---|---|
| public abstract Address[] getRecipients(Message. Get all the recipient addresses of the given type.
This method returns
| |
| getReplyTo | back to summary |
|---|---|
| public Address[] getReplyTo() throws MessagingException Get the addresses to which replies should be directed. This will usually be the sender of the message, but some messages may direct replies to a different address.
The default implementation simply calls the
This method returns
| |
| getSentDate | back to summary |
|---|---|
| public abstract Date getSentDate() throws MessagingException Get the date this message was sent.
| |
| getSession | back to summary |
|---|---|
| public Session getSession() Return the Session used when this message was created.
| |
| getSubject | back to summary |
|---|---|
| public abstract String getSubject() throws MessagingException Get the subject of this message.
| |
| isExpunged | back to summary |
|---|---|
| public boolean isExpunged() Checks whether this message is expunged. All other methods except
Messages that are expunged due to an explict
See the description of
| |
| isSet | back to summary |
|---|---|
| public boolean isSet(Flags. Check whether the flag specified in the
The default implementation uses
| |
| match | back to summary |
|---|---|
| public boolean match(SearchTerm term) throws MessagingException Apply the specified Search criterion to this message.
| |
| reply | back to summary |
|---|---|
| public abstract Message reply(boolean replyToAll) throws MessagingException Get a new Message suitable for a reply to this message. The new Message will have its attributes and headers set up appropriately. Note that this new message object will be empty, that is, it will not have a "content". These will have to be suitably filled in by the client.
If The "Subject" field is filled in with the original subject prefixed with "Re:" (unless it already starts with "Re:"). The reply message will use the same session as this message.
| |
| saveChanges | back to summary |
|---|---|
| public abstract void saveChanges() throws MessagingException Save any changes made to this message into the message-store when the containing folder is closed, if the message is contained in a folder. (Some implementations may save the changes immediately.) Update any header fields to be consistent with the changed message contents. If any part of a message's headers or contents are changed, saveChanges must be called to ensure that those changes are permanent. If saveChanges is not called, any such modifications may or may not be saved, depending on the message store and folder implementation. Messages obtained from folders opened READ_ONLY should not be modified and saveChanges should not be called on such messages.
| |
| setExpunged | back to summary |
|---|---|
| protected void setExpunged(boolean expunged) Sets the expunged flag for this Message. This method is to be used only by the implementation classes.
| |
| setFlag | back to summary |
|---|---|
| public void setFlag(Flags. Set the specified flag on this message to the specified value.
This will result in a
The default implementation uses the
| |
| setFlags | back to summary |
|---|---|
| public abstract void setFlags(Flags flag, boolean set) throws MessagingException Set the specified flags on this message to the specified value.
Note that any flags in this message that are not specified in
the given
This will result in a
| |
| setFrom | back to summary |
|---|---|
| public abstract void setFrom() throws MessagingException Set the "From" attribute in this Message. The value of this attribute is obtained from the property "mail.user". If this property is absent, the system property "user.name" is used.
| |
| setFrom | back to summary |
|---|---|
| public abstract void setFrom(Address address) throws MessagingException Set the "From" attribute in this Message.
| |
| setMessageNumber | back to summary |
|---|---|
| protected void setMessageNumber(int msgnum) Set the Message number for this Message. This method is invoked only by the implementation classes.
| |
| setRecipient | back to summary |
|---|---|
| public void setRecipient(Message. Set the recipient address. All addresses of the specified type are replaced by the address parameter.
The default implementation uses the
| |
| setRecipients | back to summary |
|---|---|
| public abstract void setRecipients(Message. Set the recipient addresses. All addresses of the specified type are replaced by the addresses parameter.
| |
| setReplyTo | back to summary |
|---|---|
| public void setReplyTo(Address[] addresses) throws MessagingException Set the addresses to which replies should be directed. (Normally only a single address will be specified.) Not all message types allow this to be specified separately from the sender of the message. The default implementation provided here just throws the MethodNotSupportedException.
| |
| setSentDate | back to summary |
|---|---|
| public abstract void setSentDate(Date date) throws MessagingException Set the sent date of this message.
| |
| setSubject | back to summary |
|---|---|
| public abstract void setSubject(String subject) throws MessagingException Set the subject of this message.
| |
Message msg = folder.getMessages(1); Address[] a = m.getRecipients(Message.RecipientType.TO);
jakarta.mail.Message#getRecipients , jakarta.mail.Message#setRecipients , jakarta.mail.Message#addRecipients
| Modifier and Type | Field and Description |
|---|---|
| public static final Message. | BCC
The "Bcc" (blind carbon copy) recipients. |
| public static final Message. | CC
The "Cc" (carbon copy) recipients. |
| private static final long | |
| public static final Message. | TO
The "To" (primary) recipients. |
| protected String | type
The type of recipient, usually the name of a corresponding Internet standard header. |
| Access | Constructor and Description |
|---|---|
| protected |
| Modifier and Type | Method and Description |
|---|---|
| protected Object | Returns: the RecipientType object instanceWhen deserializing a RecipientType, we need to make sure to return only one of the known static final instances defined in this class. |
| public String |
| BCC | back to summary |
|---|---|
| public static final Message. The "Bcc" (blind carbon copy) recipients. | |
| CC | back to summary |
|---|---|
| public static final Message. The "Cc" (carbon copy) recipients. | |
| serialVersionUID | back to summary |
|---|---|
| private static final long serialVersionUID | |
| TO | back to summary |
|---|---|
| public static final Message. The "To" (primary) recipients. | |
| type | back to summary |
|---|---|
| protected String type The type of recipient, usually the name of a corresponding Internet standard header. | |
| RecipientType | back to summary |
|---|---|
| protected RecipientType(String type) Constructor for use by subclasses.
| |
| readResolve | back to summary |
|---|---|
| protected Object readResolve() throws ObjectStreamException When deserializing a RecipientType, we need to make sure to
return only one of the known static final instances defined
in this class. Subclasses must implement their own
| |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Doc from java. Returns a string representation of the object.
Satisfying this method's contract implies a non- | |