org.apache.turbine.util.mail
Class HtmlEmail

java.lang.Object
  |
  +--org.apache.turbine.util.mail.Email
        |
        +--org.apache.turbine.util.mail.MultiPartEmail
              |
              +--org.apache.turbine.util.mail.HtmlEmail
Direct Known Subclasses:
VelocityHtmlEmail, WebMacroHtmlEmail

public class HtmlEmail
extends MultiPartEmail

An HTML multipart email.

This class is used to send HTML formatted email. A text message can also be set for HTML unaware email clients, such as text-based email clients.

This class also inherits from MultiPartEmail, so it is easy to add attachents to the email.

To send an email in HTML, one should create a HtmlEmail, then use the setFrom, addTo, etc. methods. The HTML content can be set with the setHtmlMsg method. The alternate text content can be set with setTextMsg.

Either the text or HTML can be omitted, in which case the "main" part of the multipart becomes whichever is supplied rather than a multipart/alternative.

Version:
$Id: HtmlEmail.java,v 1.1.1.1 2001/08/16 05:09:56 jvanzyl Exp $
Author:
Regis Koenig, Sean Legassick

Field Summary
protected  java.lang.String html
           
protected  javax.mail.internet.MimeMultipart htmlContent
           
protected  java.lang.String text
           
 
Fields inherited from class org.apache.turbine.util.mail.MultiPartEmail
emailBody, fileServer, main
 
Fields inherited from class org.apache.turbine.util.mail.Email
ATTACHMENTS, bccList, ccList, charset, CONTENT_TYPE, EMAIL_BODY, EMAIL_SUBJECT, FILE_SERVER, ISO_8859_1, KOI8_R, MAIL_HOST, MAIL_SERVER, MAIL_SMTP_FROM, MAIL_TRANSPORT_PROTOCOL, message, RECEIVER_EMAIL, RECEIVER_NAME, replyList, SENDER_EMAIL, SENDER_NAME, SMTP, TEXT_HTML, TEXT_PLAIN, toList, US_ASCII
 
Constructor Summary
HtmlEmail()
          Basic constructor.
 
Method Summary
 java.lang.String embed(java.net.URL url, java.lang.String name)
          Embeds an URL in the HTML.
 javax.mail.internet.MimeMultipart getHtmlContent()
          Instantiates a new MimeMultipart object if it isn't already instantiated.
 void send()
          Does the work of actually sending the email.
 HtmlEmail setHtmlMsg(org.apache.ecs.Document doc)
          Set the HTML content based on an ECS document.
 HtmlEmail setHtmlMsg(java.lang.String html)
          Set the HTML content.
 Email setMsg(java.lang.String msg)
          Set the message.
 HtmlEmail setTextMsg(java.lang.String text)
          Set the text content.
 
Methods inherited from class org.apache.turbine.util.mail.MultiPartEmail
attach, attach, attach, attach, attach, init, initCriteria
 
Methods inherited from class org.apache.turbine.util.mail.Email
addBcc, addCc, addReplyTo, addTo, getMailSession, initialize, setCharset, setFrom, setSentDate, setSubject, toInternetAddressArray
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

htmlContent

protected javax.mail.internet.MimeMultipart htmlContent

text

protected java.lang.String text

html

protected java.lang.String html
Constructor Detail

HtmlEmail

public HtmlEmail()
          throws javax.mail.MessagingException
Basic constructor.
Throws:
MessagingException. -  
Method Detail

getHtmlContent

public javax.mail.internet.MimeMultipart getHtmlContent()
Instantiates a new MimeMultipart object if it isn't already instantiated.
Returns:
A MimeMultipart object

setTextMsg

public HtmlEmail setTextMsg(java.lang.String text)
                     throws javax.mail.MessagingException
Set the text content.
Parameters:
text - A String.
Returns:
An HtmlEmail.
Throws:
MessagingException. -  

setHtmlMsg

public HtmlEmail setHtmlMsg(java.lang.String html)
                     throws javax.mail.MessagingException
Set the HTML content.
Parameters:
html - A String.
Returns:
An HtmlEmail.
Throws:
MessagingException. -  

setHtmlMsg

public HtmlEmail setHtmlMsg(org.apache.ecs.Document doc)
                     throws javax.mail.MessagingException
Set the HTML content based on an ECS document.
Parameters:
doc - A Document.
Returns:
An HtmlEmail.
Throws:
MessagingException. -  

setMsg

public Email setMsg(java.lang.String msg)
             throws javax.mail.MessagingException
Set the message.

This method overrides the MultiPartEmail setMsg() method in order to send an HTML message instead of a full text message in the mail body. The message is formatted in HTML for the HTML part of the message, it is let as is in the alternate text part.

Overrides:
setMsg in class MultiPartEmail
Parameters:
msg - A String.
Returns:
An Email.
Throws:
MessagingException. -  

embed

public java.lang.String embed(java.net.URL url,
                              java.lang.String name)
                       throws javax.mail.MessagingException
Embeds an URL in the HTML.

This method allows to embed a file located by an URL into the mail body. It allows, for instance, to add inline images to the email. Inline files may be referenced with a cid:xxxxxx URL, where xxxxxx is the Content-ID returned by the embed function.

Example of use:

 HtmlEmail he = new HtmlEmail();
 he.setHtmlMsg("<html><img src=cid:"+embed("file:/my/image.gif","image.gif")+"></html>");
 // code to set the others email fields (not shown)
 
Parameters:
url - The URL of the file.
name - The name that will be set in the filename header field.
Returns:
A String with the Content-ID of the file.
Throws:
MessagingException. -  

send

public void send()
          throws javax.mail.MessagingException
Does the work of actually sending the email.
Overrides:
send in class Email
Throws:
MessagingException, - if there was an error.


Copyright © 2000-2002 Apache Software Foundation. All Rights Reserved.