Secure iNet Factory

com.jscape.inet.email
Class EmailMessage

java.lang.Object
  extended by com.jscape.inet.mime.MimeMessage
      extended by com.jscape.inet.email.EmailMessage
All Implemented Interfaces:
MimeConstants, java.io.Serializable
Direct Known Subclasses:
HtmlEmailMessage

public class EmailMessage
extends MimeMessage

Represents an email message. Used by Smtp, Pop and Imap classes to facilitate the sending and retrieving of email.

Example Usage:

 EmailMessage message = new EmailMessage();
 message.setTo("jsmith@myserver.com");
 message.setFrom("rjones@myserver.com");
 message.setSubject("Meeting at 8");
 message.setBody("See you then");
 

See Also:
Serialized Form

Field Summary
 
Fields inherited from interface com.jscape.inet.mime.MimeConstants
COLON, CR, CRLF, EQUALS, LF, QUESTION_MARK, SEMI_COLON, SPACE, TAB
 
Constructor Summary
EmailMessage()
          Constructs an EmailMessage instance.
EmailMessage(byte[] contents)
          Contructs and EmailMessage instance from contents of contents.
EmailMessage(java.lang.String to, java.lang.String from)
          Constructs an EmailMessage instance defining to and from addresses.
EmailMessage(java.lang.String to, java.lang.String from, java.lang.String subject, java.lang.String body)
          Constructs an EmailMessage instance defining to and from addresses and subject and body of email.
 
Method Summary
 void addAttachment(Attachment attachment)
          Adds attachment to this email message.
 void addAttachment(Attachment attachment, boolean wrap)
          Adds attachment to this email message.
 java.util.Enumeration getAttachments()
          Gets all message attachments from this email message.
 java.lang.String getBcc()
          Gets Bcc address of message.
 java.lang.String getBody()
          Gets body of message.
 java.lang.String getCc()
          Gets Cc address of message.
 java.lang.String getContentType()
          Gets Content-Type header of email message.
 java.lang.String getDate()
          Gets Date of message.
 java.lang.String getFrom()
          Gets From address of message.
 byte[] getMessage()
          Gets contents of this EmailMessage.
 int getPriority()
          Gets priority of message when displayed in recipients email client.
 java.lang.String getReplyTo()
          Gets reply-to address of message.
 java.lang.String getSubject()
          Gets Subject of message.
 java.lang.String getTo()
          Gets To address of message.
 void setBcc(java.lang.String bcc)
          Sets receipient blind-carbon-copy email address.
 void setCc(java.lang.String cc)
          Sets receipient carbon-copy email address.
 void setCc(java.lang.String cc, java.lang.String characterEncoding)
          Sets receipient carbon-copy email address.
 void setContentType(java.lang.String contentType)
          Sets Content-Type header of email message.
 void setContentType(java.lang.String contentType, java.lang.String characterSet)
          Sets Content-Type header of email message.
 void setFrom(java.lang.String from)
          Sets from email address.
 void setFrom(java.lang.String from, java.lang.String characterEncoding)
          Sets from email address using defined character encoding.
 void setPriority(int priority)
          Sets priority of message when displayed in recipients email client.
 void setReplyTo(java.lang.String replyto)
          Sets message Reply-To address.
 void setReplyTo(java.lang.String replyto, java.lang.String characterEncoding)
          Sets message Reply-To address.
 void setSubject(java.lang.String subject)
          Sets message subject.
 void setSubject(java.lang.String subject, java.lang.String characterEncoding)
          Sets message subject.
 void setTo(java.lang.String to)
          Sets receipient to email address.
 void setTo(java.lang.String to, java.lang.String characterEncoding)
          Sets receipient to email address.
 
Methods inherited from class com.jscape.inet.mime.MimeMessage
addHeader, addHeader, addPart, addReplaceHeader, addReplaceHeader, getBodyAsFile, getBodyData, getBoundary, getContentTransferEncoding, getHeader, getHeaders, getHeaders, getHeaderValue, getPart, getParts, getRawBodyData, removeHeader, removePart, removeParts, setBody, setBody, setBody, setBody, setBodyAsFile
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

EmailMessage

public EmailMessage()
             throws MimeException
Constructs an EmailMessage instance. Default headers Date, MIME-Version, Message-ID, Content-Transfer-Encoding and Content-Type are added automatically

Throws:
MimeException - if a MIME related error occurs

EmailMessage

public EmailMessage(java.lang.String to,
                    java.lang.String from)
             throws MimeException
Constructs an EmailMessage instance defining to and from addresses. Default headers Date, MIME-Version, Message-ID, Content-Transfer-Encoding and Content-Type are added automatically.

Parameters:
to - the to address
from - the from address
Throws:
MimeException - if a MIME related error occurs

EmailMessage

public EmailMessage(java.lang.String to,
                    java.lang.String from,
                    java.lang.String subject,
                    java.lang.String body)
             throws MimeException
Constructs an EmailMessage instance defining to and from addresses and subject and body of email. Default headers Date, MIME-Version, Message-ID, Content-Transfer-Encoding and Content-Type are added automatically.

Parameters:
to - the to address
from - the from address
subject - the subject of the email
body - the body of the email
Throws:
MimeException - if a MIME related error occurs

EmailMessage

public EmailMessage(byte[] contents)
             throws MimeException
Contructs and EmailMessage instance from contents of contents.

Parameters:
contents - a byte[] containing contents of message
Throws:
MimeException - if a error occurs during message parse
Method Detail

getMessage

public byte[] getMessage()
                  throws MimeException
Gets contents of this EmailMessage. Contents include all MIME message headers, body and any parts.

Overrides:
getMessage in class MimeMessage
Returns:
message contents
Throws:
MimeException - if a MIME related parsing error occurs

setContentType

public void setContentType(java.lang.String contentType,
                           java.lang.String characterSet)
                    throws MimeException
Sets Content-Type header of email message. The default content type and character set for a newly created EmailMessage instance. are text/plain and us-ascii respectively

Parameters:
contentType - the content type of email message
characterSet - the character set used for content
Throws:
MimeException - if a MIME related error occurs

setContentType

public void setContentType(java.lang.String contentType)
                    throws MimeException
Sets Content-Type header of email message. The default content type and character set for a newly created EmailMessage instance. are text/plain and us-ascii respectively

Overrides:
setContentType in class MimeMessage
Parameters:
contentType - the content type of email message
Throws:
MimeException - if a MIME related error occurs

getContentType

public java.lang.String getContentType()
Gets Content-Type header of email message.

Overrides:
getContentType in class MimeMessage
Returns:
the content type

addAttachment

public void addAttachment(Attachment attachment)
                   throws MimeException
Adds attachment to this email message. If the email message does not contain any other parts (e.g. attachments) then a new part is created containing the body of the message and the current value of the Content-Type and Content-Transfer-Encoding headers. This new part along with the part representing the attachment are then added to the message and the Content-Type for the message is changed to multipart/mixed to indicate that the message contains multiple parts. If the message contains other parts (e.g. attachments) then the body IS NOT copied and the attachment is added as a new part to the message.

Due to the way that the message body is copied when adding attachments it is important that attachments be added only after the body of the message has been defined. Changing the body, Content-Type or Content-Transfer-Encoding of the message after attachments have been added may result in undesired effects.

Parameters:
attachment - the Attachment to add
Throws:
MimeException - if a MIME related error occurs

addAttachment

public void addAttachment(Attachment attachment,
                          boolean wrap)
                   throws MimeException
Adds attachment to this email message.

Parameters:
attachment - the attachment to add
wrap - true if to wrap existing body in a new part and add part to message, false to leave existing body as is
Throws:
MimeException - if a MIME related error occurs

getAttachments

public java.util.Enumeration getAttachments()
                                     throws MimeException
Gets all message attachments from this email message. Looks for all top level parts of message that have a Content-Disposition header of type attachment or inline. In addition this method also supports attachments formatted according to the MacMIME protocol specified in RFC 1740.

Returns:
an Enumeration of Attachment
Throws:
MimeException - if error occurs in decoding attachments

setFrom

public void setFrom(java.lang.String from)
             throws MimeException
Sets from email address.

Parameters:
from - the from email address
Throws:
MimeException - if a MIME related error occurs

setFrom

public void setFrom(java.lang.String from,
                    java.lang.String characterEncoding)
             throws MimeException
Sets from email address using defined character encoding. From address is encoded according to RFC 2047. This method should be used in cases where the address contains data other than US-ASCII characters.

Parameters:
from - the from email address
characterEncoding - the character encoding used
Throws:
MimeException - thrown if an error occurs while encoding From header
See Also:
MimeException

setTo

public void setTo(java.lang.String to)
           throws MimeException
Sets receipient to email address. To send to multiple recipients pass in all recipients comma delimited. Example: user@domain.com,user2@domain.com,user3@domain.com

Parameters:
to - the recipient to email address
Throws:
MimeException - if a MIME related error occurs

setTo

public void setTo(java.lang.String to,
                  java.lang.String characterEncoding)
           throws MimeException
Sets receipient to email address. To send to multiple recipients pass in all recipients comma space delimited. Example:
user@domain.com, user2@domain.com, user3@domain.com
To address is encoded according to RFC 2047. This method should be used in cases where the address contains data other than US-ASCII characters.

Parameters:
to - the to email address
characterEncoding - the character encoding used
Throws:
MimeException - thrown if an error occurs while encoding To header
See Also:
MimeException

setCc

public void setCc(java.lang.String cc)
           throws MimeException
Sets receipient carbon-copy email address. To send to multiple recipients pass in all recipients comma delimited. Example:
user@domain.com, user2@domain.com, user3@domain.com

Parameters:
cc - the recipient carbon-copy email address
Throws:
MimeException - if a MIME related error occurs

setCc

public void setCc(java.lang.String cc,
                  java.lang.String characterEncoding)
           throws MimeException
Sets receipient carbon-copy email address. To send to multiple recipients pass in all recipients comma delimited. Example:
user@domain.com, user2@domain.com, user3@domain.com
Cc address is encoded according to RFC 2047. This method should be used in cases where the address contains data other than US-ASCII characters.

Parameters:
cc - the recipient carbon-copy email address
characterEncoding - the character encoding used
Throws:
MimeException - thrown if an error occurs while encoding Cc header
See Also:
MimeException

setBcc

public void setBcc(java.lang.String bcc)
            throws MimeException
Sets receipient blind-carbon-copy email address. To send to multiple recipients pass in all recipients comma delimited. Example:
user@domain.com,user2@domain.com,user3@domain.com

Parameters:
bcc - the recipient blind-carbon-copy email address
Throws:
MimeException - if a MIME related error occurs

setReplyTo

public void setReplyTo(java.lang.String replyto,
                       java.lang.String characterEncoding)
                throws MimeException
Sets message Reply-To address.

Parameters:
replyto - the reply-to email address
characterEncoding - the character encoding to use when setting the Reply-To address
Throws:
MimeException - thrown if an error occurs while encoding Reply-To header
See Also:
MimeException

setReplyTo

public void setReplyTo(java.lang.String replyto)
                throws MimeException
Sets message Reply-To address.

Parameters:
replyto - the reply-to email address
Throws:
MimeException - if a MIME related error occurs

setSubject

public void setSubject(java.lang.String subject)
                throws MimeException
Sets message subject.

Parameters:
subject - the subject of message
Throws:
MimeException - if a MIME related error occurs

setSubject

public void setSubject(java.lang.String subject,
                       java.lang.String characterEncoding)
                throws MimeException
Sets message subject.

Parameters:
subject - the subject of message
characterEncoding - the character encoding used when setting the Subject header
Throws:
MimeException - if a MIME related error occurs

getSubject

public java.lang.String getSubject()
Gets Subject of message.

Returns:
the subject or null if no Subject header is present

getFrom

public java.lang.String getFrom()
Gets From address of message.

Returns:
the from address or null of no From header is present

getTo

public java.lang.String getTo()
Gets To address of message.

Returns:
the to address or null of no To header is present

getCc

public java.lang.String getCc()
Gets Cc address of message.

Returns:
the carbon-copy address or null of no Cc header is present

getBcc

public java.lang.String getBcc()
Gets Bcc address of message.

Returns:
the blind-carbon-copy address or null of no Bcc header is present

getDate

public java.lang.String getDate()
Gets Date of message. According to RFC 822 the Date header may come back in either of the following formats: EEE, d MMM yyyy HH:mm:ss z The day of week portion denoted as EEE is optional. Examples of formats include: Date: Fri, 16 May 2003 10:01:14 -0700 The above date includes the day of week. Date: 16 May 2003 10:01:14 -0700 The above date does not include the day of week.

Returns:
the message date or null of no Date header is present

getReplyTo

public java.lang.String getReplyTo()
Gets reply-to address of message.

Returns:
the reply-to address or null of no Reply-To header is present

getBody

public java.lang.String getBody()
                         throws MimeException
Gets body of message. If message has Content-Type header of multipart/mixed or multipart/alternative then the body returned will be that of the first message part that has a Content-Type header that is not multipart/mixed or multipart/alternative.

Overrides:
getBody in class MimeMessage
Returns:
the message body or null of no body is present
Throws:
MimeException - if a MIME related error occurs

setPriority

public void setPriority(int priority)
                 throws MimeException
Sets priority of message when displayed in recipients email client. 1 = High priority, 3 = Normal priority and 5 = Low priority.

Parameters:
priority - the message priority
Throws:
MimeException - if a MIME related error occurs while reading message

getPriority

public int getPriority()
                throws MimeException
Gets priority of message when displayed in recipients email client. 1 = High priority, 3 = Normal priority and 5 = Low priority.

Returns:
the message priority
Throws:
MimeException - if a MIME related error occurs while reading message

Secure iNet Factory

Copyright © JSCAPE LLC. 1999-2011. All Rights Reserved