org.apache.turbine.util.velocity
Class VelocityHtmlEmail
java.lang.Object
|
+--org.apache.turbine.util.mail.Email
|
+--org.apache.turbine.util.mail.MultiPartEmail
|
+--org.apache.turbine.util.mail.HtmlEmail
|
+--org.apache.turbine.util.velocity.VelocityHtmlEmail
- public class VelocityHtmlEmail
- extends HtmlEmail
This is a simple class for sending html email from within Velocity.
Essentially, the bodies (text and html) of the email are a Velocity
Context objects. The beauty of this is that you can send email
from within your Velocity template or from your business logic in
your Java code. The body of the email is just a Velocity template
so you can use all the template functionality of Velocity within
your emails!
This class allows you to send HTML email with embedded content
and/or with attachments. You can access the VelocityHtmlEmail
instance within your templates trough the $mail
Velocity variable.
VelocityHtmlEmail myEmail= new VelocityHtmlEmail(data);
context.put("mail", theMessage);
The templates should be located under your Template turbine
directory.
This class extends the HtmlEmail class. Thus, it uses the
JavaMail API and also depends on having the mail.server property
set in the TurbineResources.properties file. If you want to use
this class outside of Turbine for general processing that is also
possible by making sure to set the path to the
TurbineResources.properties. See the
TurbineResourceService.setPropertiesFileName() method for more
information.
This class is basically a conversion of the WebMacroHtmlEmail
written by Regis Koenig
- Version:
- $Id: VelocityHtmlEmail.java,v 1.2 2002/07/11 16:53:19 mpoeschl Exp $
- Author:
- Andre Schild
Fields inherited from class org.apache.turbine.util.mail.Email |
ATTACHMENTS, 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, SENDER_EMAIL, SENDER_NAME, SMTP, TEXT_HTML, TEXT_PLAIN, US_ASCII |
Method Summary |
java.lang.String |
embed(java.lang.String surl,
java.lang.String name)
Embed a file in the mail. |
java.lang.String |
getCid(java.lang.String filename)
Get the cid of an embedded file. |
void |
send()
Actually send the mail. |
VelocityHtmlEmail |
setHtmlTemplate(java.lang.String template)
Set the HTML template for the mail. |
VelocityHtmlEmail |
setTextTemplate(java.lang.String template)
Set the text template for the mail. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
VelocityHtmlEmail
public VelocityHtmlEmail(RunData data)
throws javax.mail.MessagingException
- Constructor, sets the RunData object.
- Parameters:
data
- A Turbine RunData object.- Throws:
MessagingException.
-
setHtmlTemplate
public VelocityHtmlEmail setHtmlTemplate(java.lang.String template)
- Set the HTML template for the mail. This is the Webmacro
template to execute for the HTML part. Path is relative to the
VM templates directory.
- Parameters:
template
- A String.- Returns:
- A VelocityHtmlEmail (self).
setTextTemplate
public VelocityHtmlEmail setTextTemplate(java.lang.String template)
- Set the text template for the mail. This is the Velocity
template to execute for the text part. Path is relative to the
VM templates directory
- Parameters:
template
- A String.- Returns:
- A VelocityHtmlEmail (self).
send
public void send()
throws javax.mail.MessagingException
- Actually send the mail.
- Overrides:
send
in class HtmlEmail
- Throws:
MessagingException.
-
embed
public java.lang.String embed(java.lang.String surl,
java.lang.String name)
throws javax.mail.MessagingException
- Embed a file in the mail. The file can be referenced through
its Content-ID. This function also registers the CID in an
internal map, so the embedded file can be referenced more than
once by using the getCid() function. This may be useful in a
template.
Example of template:
<html>
<!-- $mail.embed("http://server/border.gif","border.gif"); -->
<img src=$mail.getCid("border.gif")>
<p>This is your content
<img src=$mail.getCid("border.gif")>
</html>
- Parameters:
surl
- A String.name
- A String.- Returns:
- A String with the cid of the embedded file.
- Throws:
MessagingException.
- - See Also:
embed.
getCid
public java.lang.String getCid(java.lang.String filename)
- Get the cid of an embedded file.
- Parameters:
filename
- A String.- Returns:
- A String with the cid of the embedded file.
- See Also:
embed.
Copyright © 2000-2002 Apache Software Foundation. All Rights Reserved.