public class EmailMessage
extends java.lang.Object
implements java.io.Serializable
The EmailMessage class is a simplified front-end to a portion of Sun's Java Mail API.
This class and package provides an easy-to-use API for composing and sending an email message, including simple single-part and more complicated multipart email messages. Using an EmailMessage object, a caller can compose and send a message consisting of an optional text part and zero or more MIME-encoded attachments. The message can have any number of recipients. The recipients can be
in any combination.
Once created and filled, an EmailMessage can be sent multiple times, through different SMTP servers if desired. To send an EmailMessage, use an EmailTransport object.
The EmailMessage class supports both the MIME "multipart/mixed" and "multipart/alternative" message types. According to RFC 1341, the differences between the two types are as follows:
multipart/mixed | Intended for use when the body parts (i.e., the text and the attachments) are independent and intended to be displayed serially. For example, to send a text message with an attached image, you would use a "multipart/mixed" message. |
multipart/alternative | Each of the parts (i.e., the main text part and the attachments) is an alternative version of the same information. The most typical "multipart/alternative" message contains a plain text part (i.e., MIME type "text/plain") and an HTML text part. Both contain the same text, but the HTML part has a "richer" version of it. The recipient's mail client should either display the "best" version of the message, based on the user's environments and preferences; or, it should offer the user a choice of which part to view. A mail reader that's capable of displaying HTML might choose to ignore the plain text part and display only the HTML attachment; by contrast, a mail reader that cannot render HTML might choose to display only the plain text part. |
By default, an EmailMessage uses the "multipart/mixed"
mode. To use "multipart/alternative", use the
setMultipartSubtype()
method, passing it the constant value
MULTIPART_ALTERNATIVE
. Note: You cannot change the
subtype once you've added content to the message.
The following code builds and sends a message containing a simple text part and one attachment, a Zip file.
EmailMessage message = new EmailMessage(); message.setSubject ("The Zip file"); message.setText ("Joe, here's the Zip file I promised."); message.setSender (new EmailAddress ("me@example.com")); message.addTo (new EmailAddress ("joe@example.com")); message.addAttachment (new File ("stuff.zip")); SMTPEmailTransport transport = new SMTPEmailTransport ("smtp.example.com"); transport.send (message); message.clear();
As a simplified front-end, this class does have some restrictions, including the following.
For more complicated email interactions, use the Java Mail API directly.
Note: This class requires the use of the Java Activation Framework (JAF) classes (package javax.activation) and the Java Mail API (package javax.mail). It was tested with the following Java Mail API and JAF versions:
Both APIs are available from java.sun.com.
Modifier and Type | Field and Description |
---|---|
static MultipartSubtype |
MULTIPART_ALTERNATIVE
Denotes a "multipart/alternative" message.
|
static MultipartSubtype |
MULTIPART_MIXED
Denotes a "multipart/mixed" message.
|
Constructor and Description |
---|
EmailMessage()
Constructs a new EmailMessage object.
|
EmailMessage(java.lang.String sender)
Constructs a new EmailMessage object, with the specified
sender address.
|
Modifier and Type | Method and Description |
---|---|
void |
addAttachment(java.io.File file)
Add an attachment from the contents of a file.
|
void |
addAttachment(java.io.File file,
java.lang.String mimeType)
Add an attachment from the contents of a file.
|
void |
addAttachment(java.io.File file,
java.lang.String fileName,
java.lang.String mimeType)
Add an attachment from the contents of a file.
|
void |
addAttachment(java.io.InputStream is)
Add an attachment to this message from an InputStream
object.
|
void |
addAttachment(java.io.InputStream is,
java.lang.String fileName)
Add an attachment to this message from an InputStream
object.
|
void |
addAttachment(java.io.InputStream is,
java.lang.String fileName,
java.lang.String mimeType)
Add a attachment to this message from an InputStream
object.
|
void |
addAttachment(java.util.Iterator iterator)
Add a text attachment to this message from an Iterator of
String objects.
|
void |
addAttachment(java.util.Iterator iterator,
java.lang.String fileName)
Add a text attachment to this message from an Iterator of
String objects.
|
void |
addAttachment(java.util.Iterator iterator,
java.lang.String fileName,
java.lang.String mimeType)
Add a text attachment to this message from an Iterator of
String objects.
|
void |
addAttachment(java.lang.String contents)
Add a text attachment to this message.
|
void |
addAttachment(java.lang.String[] contents)
Add a text attachment to this message from an array of
String objects.
|
void |
addAttachment(java.lang.String[] contents,
java.lang.String fileName)
Add a text attachment to this message from an array of
String objects.
|
void |
addAttachment(java.lang.String[] text,
java.lang.String fileName,
java.lang.String mimeType)
Add a text attachment to this message from an array of
String objects.
|
void |
addAttachment(java.lang.String contents,
java.lang.String fileName)
Add a text attachment to this message.
|
void |
addAttachment(java.lang.String contents,
java.lang.String fileName,
java.lang.String mimeType)
Add a text attachment to this message.
|
void |
addBcc(java.util.Collection<?> emailAddresses)
Add multiple email addresses to the list of "Bcc" addresses to
receive this message.
|
void |
addBcc(EmailAddress emailAddress)
Add an email address to the list of "Bcc" (blind carbon copy)
addresses to receive this message.
|
void |
addBcc(java.lang.String emailAddress)
Add an email address to the list of "Bcc" (blind carbon copy)
addresses to receive this message.
|
void |
addBcc(java.lang.String[] emailAddresses)
Add multiple email addresses to the list of "Bcc" addresses to
receive this message.
|
void |
addCc(java.util.Collection<?> emailAddresses)
Add multiple email addresses to the list of "Cc" addresses to
receive this message.
|
void |
addCc(EmailAddress emailAddress)
Add an email address, in the form of an EmailAddress
object, to the list of "Cc" addresses to receive this message.
|
void |
addCc(java.lang.String emailAddress)
Add an email address to the list of "Cc" addresses to receive this
message.
|
void |
addCc(java.lang.String[] emailAddresses)
Add multiple email addresses to the list of "Cc" addresses to
receive this message.
|
void |
addHeader(java.lang.String header,
java.lang.String value)
Add a header to the outgoing message.
|
void |
addTo(java.util.Collection<?> emailAddresses)
Add multiple email addresses to the list of "To" addresses to
receive this message.
|
void |
addTo(EmailAddress emailAddress)
Add an email address, in the form of an EmailAddress
object, to the list of "To" addresses to receive this message.
|
void |
addTo(java.lang.String emailAddress)
Add an email address to the list of "To" addresses to receive this
message.
|
void |
addTo(java.lang.String[] emailAddresses)
Add multiple email addresses to the list of "To" addresses to
receive this message.
|
void |
clear()
Clear the message.
|
void |
clearAllAttachments()
Clear all attachments from this message.
|
void |
clearAllRecipients()
Clear all recipient addresses from this message.
|
void |
clearBcc()
Clear the list of "Bcc" addresses in this message, without clearing
the "Cc" or "To" lists.
|
void |
clearCc()
Clear the list of "Cc" addresses in this message, without clearing
the "To" or "Bcc" lists.
|
void |
clearSubject()
Clear this message's subject.
|
void |
clearText()
Clear the text portion of this message.
|
void |
clearTo()
Clear the list of "To" addresses in this message, without clearing
the "Cc" or "Bcc" lists.
|
protected void |
finalize()
Destructor.
|
java.io.InputStream |
getAttachment(int index)
Get an attachment from the message.
|
java.lang.String |
getAttachmentContentType(int index)
Get the content type (i.e., MIME type) of a given attachment.
|
java.util.Collection<EmailAddress> |
getBcc()
Get the list of "Bcc" addresses to which this message will be sent.
|
java.util.Collection<EmailAddress> |
getCc()
Get the list of "Cc" addresses to which this message will be sent.
|
MultipartSubtype |
getMultipartSubtype()
Get this message's multipart subtype value.
|
EmailAddress |
getSender()
Get the email address that will be used as the sender.
|
java.lang.String |
getSubject()
Get the subject of this message.
|
java.lang.String |
getText()
Get the text portion of the message.
|
java.util.Collection<EmailAddress> |
getTo()
Get the list of "To" addresses to which this message will be sent.
|
void |
setMultipartSubtype(MultipartSubtype subType)
Set the multipart subtype.
|
void |
setSender(EmailAddress senderAddress)
Set the sender's email address.
|
void |
setSender(java.lang.String senderAddress)
Set the sender's email address.
|
void |
setSubject(java.lang.String subject)
Set the subject of this message.
|
void |
setText(java.io.File file)
Set the text part of the message from the contents of a file.
|
void |
setText(java.io.File file,
java.lang.String mimeType)
Set the text part of the message from the contents of a file.
|
void |
setText(java.io.File file,
java.lang.String fileName,
java.lang.String mimeType)
Set the text part of the message from the contents of a file,
allowing the caller to specify the file name to use when identifying
the text part.
|
void |
setText(java.io.InputStream is)
Set the text part of the message from an InputStream
object.
|
void |
setText(java.io.InputStream is,
java.lang.String fileName)
Set the text part of the message from an InputStream
object.
|
void |
setText(java.io.InputStream is,
java.lang.String fileName,
java.lang.String mimeType)
Set the text part of the message from an InputStream
object.
|
void |
setText(java.util.Iterator iterator)
Set the text part of the message from Iterator of
String objects.
|
void |
setText(java.util.Iterator iterator,
java.lang.String mimeType)
Set the text part of the message from Iterator of
String objects.
|
void |
setText(java.util.Iterator iterator,
java.lang.String fileName,
java.lang.String mimeType)
Set the text part of the message from an Iterator of
String objects.
|
void |
setText(java.lang.String text)
Set the text part of the message from a String object.
|
void |
setText(java.lang.String[] text)
Set the text part of the message from an array of String
objects.
|
void |
setText(java.lang.String[] text,
java.lang.String fileName)
Set the text part of the message from an array of String
objects.
|
void |
setText(java.lang.String[] text,
java.lang.String fileName,
java.lang.String mimeType)
Set the text part of the message from an array of String
objects.
|
void |
setText(java.lang.String text,
java.lang.String fileName)
Set the text part of the message from a String object.
|
void |
setText(java.lang.String text,
java.lang.String fileName,
java.lang.String mimeType)
Set the text part of the message from a String object.
|
int |
totalAttachments()
Get the total number of attachments, not counting the text part,
in this message.
|
public static final MultipartSubtype MULTIPART_MIXED
setMultipartSubtype(MultipartSubtype)
public static final MultipartSubtype MULTIPART_ALTERNATIVE
setMultipartSubtype(MultipartSubtype)
public EmailMessage()
public EmailMessage(java.lang.String sender) throws EmailException
setSender(java.lang.String)
, because setSender(java.lang.String)
might be overridden
by a subclass. (Calling an overridable method from a constructor is
dangerous.)sender
- The email address of the sender. If this parameter is
null, the sender's address is built
from the system's user.name property
and the host name of the SMTP server used to send the
message.EmailException
- improperly formed email addressEmailTransport.send(EmailMessage)
protected void finalize() throws java.lang.Throwable
finalize
in class java.lang.Object
java.lang.Throwable
public void clear()
Clear the message. This method clears all fields except the SMTP host. Specifically, this method:
MULTIPART_MIXED
The cleared EmailMessage can then be used for a fresh message.
NOTE: It's a good idea to call this method when you're finished with the message; it ensures that the resources used by the message--including temporary files for certain kinds of attachments--are released. The finalizer calls this method, but the finalizer might not fire right away (and, on some platforms, in some circumstances, the finalizer may not fire at all).
clearTo()
,
clearBcc()
,
clearCc()
,
clearAllRecipients()
,
clearText()
public void addHeader(java.lang.String header, java.lang.String value)
header
- the header name (e.g., "X-Mailer", "X-Mailing-List",
etc."), without the trailing ":".value
- the value for the headerpublic void addTo(java.lang.String emailAddress) throws EmailException
moe@example.com Moe Howard <moe@example.com> "Curley Howard" <curley@example.com> larry@example.com (Larry Fine)
If you want to validate the address before calling this method, simply pass it to the constructor of an EmailAddress object.
emailAddress
- the email address to addEmailException
- improperly formed email addressaddTo(String[])
,
addTo(EmailAddress)
,
getTo()
,
clearTo()
,
addCc(java.lang.String)
,
addBcc(java.lang.String)
,
clearAllRecipients()
,
EmailAddress
public void addTo(EmailAddress emailAddress) throws EmailException
emailAddress
- the email address to addEmailException
- on erroraddTo(String[])
,
addTo(String)
,
getTo()
,
clearTo()
,
addCc(java.lang.String)
,
addBcc(java.lang.String)
,
clearAllRecipients()
,
EmailAddress
public void addTo(java.lang.String[] emailAddresses) throws EmailException
emailAddresses
- the email addresses to addEmailException
- improperly formed email addressaddTo(String)
,
addTo(Collection)
,
getTo()
,
clearTo()
,
addCc(String[])
,
addBcc(String[])
,
clearAllRecipients()
public void addTo(java.util.Collection<?> emailAddresses) throws EmailException
emailAddresses
- A Collection of the email addresses.
The Collection can contain
String or EmailAddress
objects.EmailException
- improperly formed email addressaddTo(String[])
,
addTo(String)
,
addTo(EmailAddress)
,
getTo()
,
clearTo()
,
addCc(Collection)
,
addBcc(Collection)
,
clearAllRecipients()
,
EmailAddress
public java.util.Collection<EmailAddress> getTo() throws EmailException
EmailException
- error retrieving addressesaddTo(String)
,
addTo(String[])
,
clearTo()
,
EmailAddress
public void clearTo()
addTo(String)
,
addTo(String[])
,
getTo()
,
clearCc()
,
clearBcc()
,
clearAllRecipients()
public void addCc(java.lang.String emailAddress) throws EmailException
moe@example.com Moe Howard <moe@example.com> "Curley Howard" <curley@example.com> larry@example.com (Larry Fine)
If you want to validate the address before calling this method, simply pass it to the constructor of an EmailAddress object.
emailAddress
- the email address to addEmailException
- improperly formed email addressaddCc(String[])
,
addCc(EmailAddress)
,
getCc()
,
clearCc()
,
addTo(String)
,
addBcc(String)
,
clearAllRecipients()
,
EmailAddress
public void addCc(EmailAddress emailAddress) throws EmailException
emailAddress
- the email address to addEmailException
- improperly formed email addressaddCc(String[])
,
addCc(String)
,
getCc()
,
clearCc()
,
addTo(String)
,
addBcc(String)
,
clearAllRecipients()
,
EmailAddress
public void addCc(java.lang.String[] emailAddresses) throws EmailException
emailAddresses
- the email addresses to addEmailException
- improperly formed email addressaddCc(String)
,
addCc(Collection)
,
getTo()
,
clearTo()
,
addTo(String[])
,
addBcc(String[])
,
clearAllRecipients()
public void addCc(java.util.Collection<?> emailAddresses) throws EmailException
emailAddresses
- A Collection of the email addresses.
The Collection can contain
String or EmailAddress
objects.EmailException
- improperly formed email addressaddCc(String[])
,
addCc(String)
,
addCc(EmailAddress)
,
getCc()
,
clearCc()
,
addTo(Collection)
,
addBcc(Collection)
,
clearAllRecipients()
,
EmailAddress
public java.util.Collection<EmailAddress> getCc() throws EmailException
EmailException
- error retrieving addressesaddCc(String)
,
addCc(String[])
,
clearCc()
,
EmailAddress
public void clearCc()
addCc(String)
,
addCc(String[])
,
getCc()
,
clearTo()
,
clearBcc()
,
clearAllRecipients()
public void addBcc(java.lang.String emailAddress) throws EmailException
moe@example.com Moe Howard <moe@example.com> "Curley Howard" <curley@example.com> larry@example.com (Larry Fine)
If you want to validate the address before calling this method, simply pass it to the constructor of an EmailAddress object.
emailAddress
- the email address to addEmailException
- improperly formed email addressaddBcc(String[])
,
addBcc(EmailAddress)
,
getBcc()
,
clearBcc()
,
addCc(String)
,
addTo(String)
,
clearAllRecipients()
,
EmailAddress
public void addBcc(EmailAddress emailAddress) throws EmailException
emailAddress
- the email address to addEmailException
- improperly formed email addressaddBcc(String[])
,
addBcc(String)
,
getBcc()
,
clearBcc()
,
addCc(String)
,
addTo(String)
,
clearAllRecipients()
,
EmailAddress
public void addBcc(java.lang.String[] emailAddresses) throws EmailException
emailAddresses
- the email addresses to addEmailException
- improperly formed email addressaddBcc(String)
,
addBcc(Collection)
,
getTo()
,
clearTo()
,
addTo(Collection)
,
addCc(Collection)
,
clearAllRecipients()
public void addBcc(java.util.Collection<?> emailAddresses) throws EmailException
emailAddresses
- A Collection of the email addresses.
The Collection can contain
String or EmailAddress
objects.EmailException
- improperly formed email addressaddBcc(String[])
,
addBcc(String)
,
addBcc(EmailAddress)
,
getBcc()
,
clearBcc()
,
addTo(Collection)
,
addCc(Collection)
,
clearAllRecipients()
,
EmailAddress
public java.util.Collection<EmailAddress> getBcc() throws EmailException
EmailException
- error retrieving addressesaddBcc(String)
,
addBcc(String[])
,
clearBcc()
,
EmailAddress
public void clearBcc()
addBcc(String)
,
addBcc(String[])
,
getBcc()
,
clearCc()
,
clearTo()
,
clearAllRecipients()
public void clearAllRecipients()
message.clearTo(); message.clearCc(); message.clearBcc();
public void setMultipartSubtype(MultipartSubtype subType) throws EmailException
Set the multipart subtype. By default, the multipart subtype is set to MultipartSubtype.MIXED; that is, the text and the attachments are distinct, separate items. The only other possible value is MultipartSubtype.ALTERNATIVE, which signifies that each of the parts is an "alternative" version of the same information. See the class documentation for more details.
Note: You must set the subtype before adding the text part and any attachments! The attachments are encoded as you add them to the message, and the encoded format can differ depending on the subtype.
subType
- the desired subtypeEmailException
- message already has attachments, so subtype
cannot be changedgetMultipartSubtype()
,
MULTIPART_MIXED
,
MULTIPART_ALTERNATIVE
public MultipartSubtype getMultipartSubtype()
setMultipartSubtype(org.clapper.util.mail.MultipartSubtype)
public java.lang.String getText() throws EmailException
EmailException
- on errorsetText(String)
,
setText(String,String)
,
setText(String,String,String)
,
setText(String[],String,String)
,
setText(InputStream,String)
,
setText(InputStream,String,String)
,
setText(Iterator)
,
setText(Iterator,String)
,
setText(Iterator,String,String)
,
setText(File)
public void setText(java.lang.String text) throws EmailException
text
- The string to use as the text of the message. It may
contain multiple lines.EmailException
- error setting text part of messagegetText()
,
setText(String,String)
,
setText(String,String,String)
,
setText(String[],String)
,
setText(String[],String,String)
,
setText(InputStream,String)
,
setText(InputStream,String,String)
,
setText(Iterator)
,
setText(Iterator,String)
,
setText(Iterator,String,String)
,
setText(File)
,
setText(File,String)
,
clearText()
public void setText(java.lang.String text, java.lang.String fileName) throws EmailException
text
- The string to use as the text of the message. It may
contain multiple lines.fileName
- File name to associate with attachment, or null for
generated oneEmailException
- error setting text part of messagegetText()
,
setText(String,String,String)
,
setText(String[],String)
,
setText(String[],String,String)
,
setText(InputStream,String)
,
setText(InputStream,String,String)
,
setText(Iterator)
,
setText(Iterator,String)
,
setText(Iterator,String,String)
,
setText(File)
,
setText(File,String)
,
clearText()
public void setText(java.lang.String text, java.lang.String fileName, java.lang.String mimeType) throws EmailException
text
- The string to use as the text of the message. It may
contain multiple lines.fileName
- File name to associate with attachment, or null for
generated onemimeType
- The MIME type for the textEmailException
- error setting text part of messagegetText()
,
setText(String,String)
,
setText(String[],String)
,
setText(String[],String,String)
,
setText(InputStream,String)
,
setText(InputStream,String,String)
,
setText(Iterator)
,
setText(Iterator,String)
,
setText(Iterator,String,String)
,
setText(File)
,
setText(File,String)
,
clearText()
public void setText(java.lang.String[] text) throws EmailException
text
- The strings to use as the text of the message.EmailException
- error setting text part of messagegetText()
,
setText(String,String)
,
setText(String,String,String)
,
setText(String[],String)
,
setText(String[],String,String)
,
setText(InputStream,String)
,
setText(InputStream,String,String)
,
setText(Iterator)
,
setText(Iterator,String)
,
setText(Iterator,String,String)
,
setText(File)
,
setText(File,String)
,
clearText()
public void setText(java.lang.String[] text, java.lang.String fileName) throws EmailException
text
- The strings to use as the text of the message.fileName
- The file name for the attachmentEmailException
- error setting text part of messagegetText()
,
setText(String,String)
,
setText(String,String,String)
,
setText(String[])
,
setText(String[],String,String)
,
setText(InputStream,String)
,
setText(InputStream,String,String)
,
setText(Iterator)
,
setText(Iterator,String)
,
setText(Iterator,String,String)
,
setText(File)
,
setText(File,String)
,
clearText()
public void setText(java.lang.String[] text, java.lang.String fileName, java.lang.String mimeType) throws EmailException
text
- The strings to use as the text of the message.fileName
- File name to associate with attachment, or null for
generated onemimeType
- The MIME type for the textEmailException
- error setting text part of messagegetText()
,
setText(String,String)
,
setText(String,String,String)
,
setText(String[])
,
setText(String[],String)
,
setText(String[],String,String)
,
setText(InputStream,String)
,
setText(InputStream,String,String)
,
setText(Iterator)
,
setText(Iterator,String)
,
setText(Iterator,String,String)
,
setText(File)
,
setText(File,String)
,
clearText()
public void setText(java.io.InputStream is) throws EmailException
is
- The InputStream whose contents are to be read
and fed into the text part of this messageEmailException
- error setting text part of messagegetText()
,
setText(String,String)
,
setText(String,String,String)
,
setText(String[],String,String)
,
setText(InputStream,String)
,
setText(InputStream,String,String)
,
setText(Iterator)
,
setText(Iterator,String)
,
setText(Iterator,String,String)
,
setText(File,String)
,
setText(File)
,
clearText()
public void setText(java.io.InputStream is, java.lang.String fileName) throws EmailException
is
- The InputStream whose contents are to be read
and fed into the text part of this messagefileName
- File name to associate with attachment, or null for
generated oneEmailException
- error setting text part of messagegetText()
,
setText(String,String)
,
setText(String,String,String)
,
setText(String[],String,String)
,
setText(InputStream,String)
,
setText(InputStream,String,String)
,
setText(Iterator)
,
setText(Iterator,String)
,
setText(Iterator,String,String)
,
setText(File,String)
,
setText(File)
,
clearText()
public void setText(java.io.InputStream is, java.lang.String fileName, java.lang.String mimeType) throws EmailException
is
- The InputStream whose contents are to be read
and fed into the text part of this messagefileName
- File name to associate with attachment, or null for
generated onemimeType
- The MIME type for the textEmailException
- error setting text part of messagegetText()
,
setText(String,String)
,
setText(String,String,String)
,
setText(String[],String,String)
,
setText(InputStream,String)
,
setText(InputStream,String,String)
,
setText(Iterator)
,
setText(Iterator,String)
,
setText(Iterator,String,String)
,
setText(File)
,
setText(File,String)
,
clearText()
public void setText(java.util.Iterator iterator) throws EmailException
iterator
- The Iterator that will return the
String objects that represent the text linesEmailException
- error setting text part of messagegetText()
,
setText(String,String)
,
setText(String,String,String)
,
setText(String[],String,String)
,
setText(InputStream,String)
,
setText(InputStream,String,String)
,
setText(Iterator,String)
,
setText(Iterator,String,String)
,
setText(File)
,
setText(File,String)
,
clearText()
public void setText(java.util.Iterator iterator, java.lang.String mimeType) throws EmailException
iterator
- The Iterator that will return the
String objects that represent the text linesmimeType
- The MIME type for the textEmailException
- error setting text part of messagegetText()
,
setText(String,String)
,
setText(String,String,String)
,
setText(String[],String,String)
,
setText(InputStream,String)
,
setText(InputStream,String,String)
,
setText(Iterator)
,
setText(Iterator,String,String)
,
setText(File)
,
setText(File,String)
,
clearText()
public void setText(java.util.Iterator iterator, java.lang.String fileName, java.lang.String mimeType) throws EmailException
iterator
- The Iterator that will return the
String objects that represent the text linesfileName
- File name to associate with attachment, or null for
generated onemimeType
- The MIME type for the textEmailException
- error setting text part of messagegetText()
,
setText(String,String)
,
setText(String,String,String)
,
setText(String[],String,String)
,
setText(InputStream,String)
,
setText(InputStream,String,String)
,
setText(Iterator)
,
setText(Iterator,String)
,
setText(File)
,
setText(File,String)
,
clearText()
public void setText(java.io.File file) throws EmailException
file
- The File object from which to get the textEmailException
- error setting text part of messagegetText()
,
setText(File,String)
,
setText(String,String)
,
setText(String,String,String)
,
setText(String[],String,String)
,
setText(InputStream,String)
,
setText(InputStream,String,String)
,
setText(Iterator)
,
setText(Iterator,String)
,
setText(Iterator,String,String)
,
clearText()
public void setText(java.io.File file, java.lang.String mimeType) throws EmailException
file
- The File object from which to get the textmimeType
- The MIME type to associate with the text part, or
null to assume the default based on the file extensionEmailException
- error setting text part of messagegetText()
,
setText(File)
,
setText(String,String)
,
setText(String,String,String)
,
setText(String[],String,String)
,
setText(InputStream,String)
,
setText(InputStream,String,String)
,
setText(Iterator)
,
setText(Iterator,String)
,
setText(Iterator,String,String)
,
clearText()
public void setText(java.io.File file, java.lang.String fileName, java.lang.String mimeType) throws EmailException
file
- The File object from which to get the textfileName
- The file name to usemimeType
- The MIME type to associate with the text part, or
null to assume the default based on the file extensionEmailException
- error setting text part of messagegetText()
,
setText(File)
,
setText(String,String)
,
setText(String,String,String)
,
setText(String[],String,String)
,
setText(InputStream,String)
,
setText(InputStream,String,String)
,
setText(Iterator)
,
setText(Iterator,String)
,
setText(Iterator,String,String)
,
clearText()
public void clearText()
getText()
,
setText(String)
,
setText(String,String)
,
setText(String,String,String)
,
setText(String[],String)
,
setText(String[],String,String)
,
setText(InputStream)
,
setText(InputStream,String)
,
setText(InputStream,String,String)
,
setText(Iterator)
,
setText(Iterator,String)
,
setText(Iterator,String,String)
,
setText(File)
,
clearAllAttachments()
public java.io.InputStream getAttachment(int index) throws java.lang.ArrayIndexOutOfBoundsException, EmailException
index
- The 0-based index of the attachment. Index 0 corresponds
to the first attachment (not including the text part),
index 1 corresponds to the second attachment, etc.java.lang.ArrayIndexOutOfBoundsException
- index is out of rangeEmailException
- error retrieving attachmentgetAttachmentContentType(int)
,
totalAttachments()
,
addAttachment(String,String)
,
addAttachment(String,String,String)
,
addAttachment(String[],String)
,
addAttachment(String[],String,String)
,
addAttachment(InputStream,String)
,
addAttachment(InputStream,String,String)
,
addAttachment(Iterator,String)
,
addAttachment(Iterator,String,String)
,
addAttachment(File)
,
addAttachment(File,String)
public java.lang.String getAttachmentContentType(int index) throws java.lang.ArrayIndexOutOfBoundsException, EmailException
index
- The 0-based index of the attachment. Index 0 corresponds
to the first attachment (not including the text part),
index 1 corresponds to the second attachment, etc.java.lang.ArrayIndexOutOfBoundsException
- index is out of rangeEmailException
- error retrieving attachmentgetAttachment(int)
,
totalAttachments()
,
addAttachment(String,String)
,
addAttachment(String,String,String)
,
addAttachment(String[],String)
,
addAttachment(String[],String,String)
,
addAttachment(InputStream,String)
,
addAttachment(InputStream,String,String)
,
addAttachment(Iterator,String)
,
addAttachment(Iterator,String,String)
,
addAttachment(File)
,
addAttachment(File,String)
public int totalAttachments()
getAttachment(int)
,
getAttachmentContentType(int)
,
addAttachment(String,String)
,
addAttachment(String,String,String)
,
addAttachment(String[],String)
,
addAttachment(String[],String,String)
,
addAttachment(InputStream,String)
,
addAttachment(InputStream,String,String)
,
addAttachment(Iterator,String)
,
addAttachment(Iterator,String,String)
,
addAttachment(File)
,
addAttachment(File,String)
public void addAttachment(java.lang.String contents) throws EmailException
contents
- The string to use as the attachment's contents. It may
contain multiple lines.EmailException
- error creating the attachmentaddAttachment(String,String)
,
addAttachment(String[],String)
,
addAttachment(String[],String,String)
,
addAttachment(InputStream,String)
,
addAttachment(InputStream,String,String)
,
addAttachment(Iterator,String)
,
addAttachment(Iterator,String,String)
,
addAttachment(File)
,
addAttachment(File,String)
,
getAttachment(int)
,
getAttachmentContentType(int)
,
totalAttachments()
public void addAttachment(java.lang.String contents, java.lang.String fileName) throws EmailException
contents
- The string to use as the attachment's contents. It may
contain multiple lines.fileName
- The file name for the attachmentEmailException
- error creating the attachmentaddAttachment(String,String)
,
addAttachment(String[],String)
,
addAttachment(String[],String,String)
,
addAttachment(InputStream,String)
,
addAttachment(InputStream,String,String)
,
addAttachment(Iterator,String)
,
addAttachment(Iterator,String,String)
,
addAttachment(File)
,
addAttachment(File,String)
,
getAttachment(int)
,
getAttachmentContentType(int)
,
totalAttachments()
public void addAttachment(java.lang.String contents, java.lang.String fileName, java.lang.String mimeType) throws EmailException
contents
- The string to use as the attachment's contents. It may
contain multiple lines.fileName
- The file name for the attachmentmimeType
- The MIME type for the attachmentEmailException
- error adding the attachmentaddAttachment(String,String)
,
addAttachment(String[],String)
,
addAttachment(String[],String,String)
,
addAttachment(InputStream,String)
,
addAttachment(InputStream,String,String)
,
addAttachment(Iterator,String)
,
addAttachment(Iterator,String,String)
,
addAttachment(File)
,
addAttachment(File,String)
,
getAttachment(int)
,
getAttachmentContentType(int)
,
totalAttachments()
public void addAttachment(java.lang.String[] contents) throws EmailException
contents
- The strings to use as the attachment's contentsEmailException
- error adding the attachmentaddAttachment(String,String)
,
addAttachment(String,String,String)
,
addAttachment(String[],String,String)
,
addAttachment(InputStream,String)
,
addAttachment(InputStream,String,String)
,
addAttachment(Iterator,String)
,
addAttachment(Iterator,String,String)
,
addAttachment(File)
,
addAttachment(File,String)
,
getAttachment(int)
,
getAttachmentContentType(int)
,
totalAttachments()
public void addAttachment(java.lang.String[] contents, java.lang.String fileName) throws EmailException
contents
- The strings to use as the attachment's contentsfileName
- The file name for the attachmentEmailException
- error adding the attachmentaddAttachment(String,String)
,
addAttachment(String,String,String)
,
addAttachment(String[],String,String)
,
addAttachment(InputStream,String)
,
addAttachment(InputStream,String,String)
,
addAttachment(Iterator,String)
,
addAttachment(Iterator,String,String)
,
addAttachment(File)
,
addAttachment(File,String)
,
getAttachment(int)
,
getAttachmentContentType(int)
,
totalAttachments()
public void addAttachment(java.lang.String[] text, java.lang.String fileName, java.lang.String mimeType) throws EmailException
text
- The strings to use as the text of the message.fileName
- The file name for the attachmentmimeType
- The MIME type for the textEmailException
- error adding the attachmentaddAttachment(String,String)
,
addAttachment(String,String,String)
,
addAttachment(String[],String,String)
,
addAttachment(InputStream,String)
,
addAttachment(InputStream,String,String)
,
addAttachment(Iterator,String)
,
addAttachment(Iterator,String,String)
,
addAttachment(File)
,
getAttachment(int)
,
getAttachmentContentType(int)
,
totalAttachments()
public void addAttachment(java.io.InputStream is) throws EmailException
is
- The InputStream whose contents are to be read
to create the attachmentEmailException
- error adding the attachmentaddAttachment(String)
,
addAttachment(String,String)
,
addAttachment(String[],String)
,
addAttachment(InputStream)
,
addAttachment(InputStream,String)
,
addAttachment(Iterator)
,
addAttachment(Iterator,String)
,
addAttachment(File)
,
addAttachment(File,String)
,
getAttachment(int)
,
getAttachmentContentType(int)
,
totalAttachments()
public void addAttachment(java.io.InputStream is, java.lang.String fileName) throws EmailException
is
- The InputStream whose contents are to be read
to create the attachmentfileName
- the file name to use for the attachment, or null for
a generated oneEmailException
- error adding the attachmentaddAttachment(String)
,
addAttachment(String,String)
,
addAttachment(String[],String)
,
addAttachment(InputStream)
,
addAttachment(InputStream,String)
,
addAttachment(Iterator)
,
addAttachment(Iterator,String)
,
addAttachment(File)
,
addAttachment(File,String)
,
getAttachment(int)
,
getAttachmentContentType(int)
,
totalAttachments()
public void addAttachment(java.io.InputStream is, java.lang.String fileName, java.lang.String mimeType) throws EmailException
is
- The InputStream whose contents are to be read
to create the attachmentfileName
- The file name for the attachmentmimeType
- The MIME typeEmailException
- error adding the attachmentaddAttachment(String)
,
addAttachment(String,String)
,
addAttachment(String[],String)
,
addAttachment(InputStream)
,
addAttachment(InputStream,String)
,
addAttachment(Iterator)
,
addAttachment(Iterator,String)
,
addAttachment(File)
,
addAttachment(File,String)
,
getAttachment(int)
,
getAttachmentContentType(int)
,
totalAttachments()
public void addAttachment(java.util.Iterator iterator) throws EmailException
iterator
- The Iterator that will return the
String objects that represent the text linesEmailException
- error adding the attachmentaddAttachment(String)
,
addAttachment(String,String)
,
addAttachment(String[],String)
,
addAttachment(InputStream)
,
addAttachment(InputStream,String)
,
addAttachment(Iterator,String)
,
addAttachment(File)
,
addAttachment(File,String)
,
getAttachment(int)
,
getAttachmentContentType(int)
,
totalAttachments()
public void addAttachment(java.util.Iterator iterator, java.lang.String fileName) throws EmailException
iterator
- The Iterator that will return the
String objects that represent the text linesfileName
- The file name for the attachmentEmailException
- error adding the attachmentaddAttachment(String)
,
addAttachment(String,String)
,
addAttachment(String[],String)
,
addAttachment(InputStream)
,
addAttachment(InputStream,String)
,
addAttachment(Iterator,String)
,
addAttachment(File)
,
addAttachment(File,String)
,
getAttachment(int)
,
getAttachmentContentType(int)
,
totalAttachments()
public void addAttachment(java.util.Iterator iterator, java.lang.String fileName, java.lang.String mimeType) throws EmailException
iterator
- The Iterator that will return the
String objects that represent the text linesfileName
- The file name for the attachment, or null to use
a generated one.mimeType
- The MIME type for the textEmailException
- error adding the attachmentaddAttachment(String)
,
addAttachment(String,String)
,
addAttachment(String[],String)
,
addAttachment(InputStream)
,
addAttachment(InputStream,String)
,
addAttachment(Iterator)
,
addAttachment(File)
,
addAttachment(File,String)
,
getAttachment(int)
,
getAttachmentContentType(int)
,
totalAttachments()
public void addAttachment(java.io.File file) throws EmailException
file
- The File to read to create the attachmentEmailException
- error adding the attachmentaddAttachment(File,String)
,
addAttachment(String)
,
addAttachment(String,String)
,
addAttachment(String[],String)
,
addAttachment(InputStream)
,
addAttachment(InputStream,String)
,
addAttachment(Iterator)
,
getAttachment(int)
,
getAttachmentContentType(int)
,
totalAttachments()
public void addAttachment(java.io.File file, java.lang.String mimeType) throws EmailException
file
- The File to read to create the attachmentmimeType
- The MIME type to associate with the file, or null
to infer the MIME type from the file's extensionEmailException
- error adding the attachmentaddAttachment(File,String)
,
addAttachment(String)
,
addAttachment(String,String)
,
addAttachment(String[],String)
,
addAttachment(InputStream)
,
addAttachment(InputStream,String)
,
addAttachment(Iterator)
,
getAttachment(int)
,
getAttachmentContentType(int)
,
totalAttachments()
public void addAttachment(java.io.File file, java.lang.String fileName, java.lang.String mimeType) throws EmailException
file
- The File to read to create the attachmentfileName
- The file name to use as the attachment namemimeType
- The MIME type to associate with the file, or null
to infer the MIME type from the file's extensionEmailException
- error adding the attachmentaddAttachment(File,String)
,
addAttachment(String)
,
addAttachment(String,String)
,
addAttachment(String[],String)
,
addAttachment(InputStream)
,
addAttachment(InputStream,String)
,
addAttachment(Iterator)
,
getAttachment(int)
,
getAttachmentContentType(int)
,
totalAttachments()
public void clearAllAttachments()
public void setSubject(java.lang.String subject)
subject
- The text subject of the message, or null to clear
the subjectgetSubject()
,
clearSubject()
public java.lang.String getSubject()
setSubject(String)
,
clearSubject()
public void clearSubject()
setSubject(String)
,
getSubject()
public void setSender(java.lang.String senderAddress) throws EmailException
vangogh@example.com Vincent Van Gogh <vangogh@example.com> "Vincent Van Gogh" <vangogh@example.com> vangogh@example.com (Vincent Van Gogh)
senderAddress
- the new sender address value, or null to
clear the sender (and force it to be computed
as described above)EmailException
- improperly formed email addresssetSender(EmailAddress)
public void setSender(EmailAddress senderAddress) throws EmailException
vangogh@example.com Vincent Van Gogh <vangogh@example.com> "Vincent Van Gogh" <vangogh@example.com> vangogh@example.com (Vincent Van Gogh)
senderAddress
- the new sender address value, or null to
clear the sender (and force it to be computed
as described above)EmailException
- improperly formed email addresssetSender(String)
public EmailAddress getSender() throws EmailException
EmailException
- error calculating sender addressEmailAddress