Secure iNet Factory

com.jscape.inet.email
Class HtmlEmailMessage

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

public class HtmlEmailMessage
extends EmailMessage

Represents an email message that contains both HTML and plain text parts.

Example Usage:

 HtmlEmailMessage message = new HtmlEmailMessage();
 message.setTo("jsmith@myserver.com");
 message.setFrom("rjones@myserver.com");
 message.setSubject("Meeting at 8");
 message.setTextBody("this is the text body");
 message.setHtmlBody("<html><body><img src=\"cid:12345\"><br>this is the html body</body></html>");
 message.embed(new URL("http://www.domain.com/image.gif","12345");
 

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
HtmlEmailMessage()
          Creates a new HtmlEmailMessage instance.
 
Method Summary
 void addAttachment(Attachment att)
          Adds attachment to email message.
 void embed(java.io.File file, java.lang.String id)
          Embeds a resource in the email message.
 void embed(java.net.URL url, java.lang.String id)
          Embeds a resource in the email message.
 byte[] getMessage()
          Gets contents of this HtmlEmailMessage.
 void setHtmlBody(java.io.File htmlBody)
          Sets the HTML portion of this email message from contents of a file.
 void setHtmlBody(java.lang.String htmlBody)
          Sets the HTML portion of this email message.
 void setTextBody(java.io.File textBody)
          Sets the plain text portion of this email message from contents of a file.
 void setTextBody(java.lang.String textBody)
          Sets the plain text portion of this email message.
 
Methods inherited from class com.jscape.inet.email.EmailMessage
addAttachment, getAttachments, getBcc, getBody, getCc, getContentType, getDate, getFrom, getPriority, getReplyTo, getSubject, getTo, setBcc, setCc, setCc, setContentType, setContentType, setFrom, setFrom, setPriority, setReplyTo, setReplyTo, setSubject, setSubject, setTo, setTo
 
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

HtmlEmailMessage

public HtmlEmailMessage()
                 throws MimeException
Creates a new HtmlEmailMessage instance.

Throws:
MimeException - if a MIME related error occurs
Method Detail

addAttachment

public void addAttachment(Attachment att)
                   throws MimeException
Adds attachment to email message. Invokes the parent EmailMessage#addAttachment(Attachment,boolean) method providing the attachment and false as method argument to ensure that existing body is not added as a separate MIME part.

Overrides:
addAttachment in class EmailMessage
Parameters:
att - the attachment to add
Throws:
MimeException - if a MIME related error occurs

setTextBody

public void setTextBody(java.lang.String textBody)
Sets the plain text portion of this email message. Text portion will be displayed by mail clients that are not capable of displaying HTML or have HTML display disabled.

Parameters:
textBody - the plain text portion of this message

setHtmlBody

public void setHtmlBody(java.lang.String htmlBody)
Sets the HTML portion of this email message. HTML portion will be displayed by mail clients that are capable of displaying HTML and have HTML display enabled.

Parameters:
htmlBody - the HTML portion of this message

setHtmlBody

public void setHtmlBody(java.io.File htmlBody)
                 throws java.io.IOException
Sets the HTML portion of this email message from contents of a file. HTML portion will be displayed by mail clients that are capable of displaying HTML and have HTML display enabled.

Parameters:
htmlBody - file containing HTML body
Throws:
java.io.IOException - if an I/O error occurs

setTextBody

public void setTextBody(java.io.File textBody)
                 throws java.io.IOException
Sets the plain text portion of this email message from contents of a file. Text portion will be displayed by mail clients that are not capable of displaying HTML or have HTML display disabled.

Parameters:
textBody - file containing text body
Throws:
java.io.IOException - if an I/O error occurs

embed

public void embed(java.net.URL url,
                  java.lang.String id)
Embeds a resource in the email message.

Parameters:
url - the URL of the resource
id - the unique Content-ID header value of the resource referenced in the HTML code

embed

public void embed(java.io.File file,
                  java.lang.String id)
Embeds a resource in the email message.

Parameters:
file - the resource file
id - the unique Content-ID header value of the resource referenced in the HTML code

getMessage

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

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

Secure iNet Factory

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