public class MailComposer extends Object
MailComposer.java Created on February 28, 2013 This class can be used to compose e-mails in a manner very similar to how it is done on the PC. The composer is constructed and the user may define the addressing, content and even attachments in any order finally issuing (or canceling) the email with a Send(). MIME Version 1.0 is used in transmitting multi-part/mixed e-mail to included any number of file attachments. Attachments may be either text or binary. The minimum requirement is that the user set the "To:" addressing. The latter is also the "Reply To:" address and should be a valid address within the domain of the Mail Host. Note that JNIOR cannot retrieve e-mail and therefore cannot process replies directly. The following example shows the minimum usage (no message content relying on the subject line to convey the message): MailComposer compose = new MailComposer(); compose.setToAddress( "bcloutier@integpg.com" ); compose.Send(); The following methods optionally augment the message and can be called prior to Send(). compose.setSubject( "message from JNIOR" ); compose.setCcAddress( "rshulkosky@integpg.com" ); compose.setBccAddress( "rshulkosky@integpg.com" ); compose.setMessage( "The jniorboot.log file has been attached." ); compose.setAttachment( "/jniorsys.log" ); The "To", "CC" and "BCC" addressing may contain multiple e-mail addresses separated by commas. A message may contain any number of attachments with each attachment being appended by repeated setAttachment() calls (i.e. each call appends an attachment - it doesn't replace a prior one). Note that setMessage() will take either a String or a byte[] object.
Constructor and Description |
---|
MailComposer()
Creates new MailComposer
|
Modifier and Type | Method and Description |
---|---|
protected void |
finalize()
We need to release the handle if the message has not been sent
|
void |
reset()
Resets the composer ready to define a new message.
|
boolean |
send()
This transmits the composed e-mail.
|
void |
setAttachment(String filespec)
This adds a file to the attachment list.
|
void |
setAttachment(String filespec,
String ctype,
boolean encode)
This adds a file to the attachment list.
|
void |
setBccAddress(String[] bcc)
Defines the "Blind Copy" addressing for this message if any.
|
void |
setCcAddress(String[] cc)
Defines the "CC" addressing for this message if any.
|
void |
setMessage(byte[] bufr)
This defines the content for this message.
|
void |
setMessage(String message)
This defines the content for this message.
|
void |
setMessageFile(String filespec)
This defines the content for this message.
|
void |
setMessageHTML(byte[] bufr)
This defines the content for this message.
|
void |
setMessageHTML(String message)
This defines the content for this message.
|
void |
setSubject(String subject)
Defines the Subject for this message.
|
void |
setToAddress(String to)
Defines the destination addressing for this message.
|
void |
setToAddress(String[] to)
Defines the destination addressing for this message.
|
public boolean send()
public void reset()
public void setToAddress(String to)
to
- Defines the 'To:' addressing for the current message.public void setToAddress(String[] to)
to
- Defines the 'To:' addressing for the current message. May
specify multiple addresses.public void setCcAddress(String[] cc)
cc
- Defines the 'cc:' addressing to be applied to the current message. This may
contain multiple addresses. This addressing is optional.public void setBccAddress(String[] bcc)
bcc
- Defines the 'bcc:' addressing to be applied to the current message.
This may contain multiple addresses. This addressing is optional.public void setSubject(String subject)
subject
- Provides the subject line for the current message.public void setMessage(String message)
message
- Conveys the message content which is assumed to be
straight text. This content is optional.public void setMessage(byte[] bufr)
bufr
- Conveys the message content which is assumed to be
straight text. This content is optional.public void setMessageFile(String filespec)
filespec
- Indicates the file that conveys the message content which
is assumed to be straight text. This content is optional and appended to
defined textual message content.public void setMessageHTML(String message)
message
- Conveys the message content which is assumed to be HTML.
This content is optional.public void setMessageHTML(byte[] bufr)
bufr
- Conveys the message content which is assumed to be HTML.
This content is optional.public void setAttachment(String filespec)
filespec
- Specifies the file to be attached. One file is attached to
the current message for each call to setAttachment(). Multiple files may
be associated with a single message.public void setAttachment(String filespec, String ctype, boolean encode)
filespec
- Specifies the file to be attached. One file is attached to
the current message for each call to setAttachment(). Multiple files may
be associated with a single message.ctype
- Specifies the MIME Content-Type to be used with this
attachment.encode
- When true (default) the associated attachment will be
encoded using base64 encoding. This is most reliable and required for
binary attachments. This may be set to false to attach the file
as straight text.