|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
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
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
Field Summary | |
private RunData |
data
The cached rundata object. |
private java.util.Hashtable |
embmap
The map of embedded files. |
private java.lang.String |
htmlTemplate
The html template to process, relative to VM's template directory. |
private java.lang.String |
textTemplate
The text template to process, relative to VM's template directory. |
Fields inherited from class org.apache.turbine.util.mail.HtmlEmail |
html, htmlContent, 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 | |
VelocityHtmlEmail(RunData data)
Constructor, sets the RunData object. |
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. |
private static org.apache.velocity.context.Context |
getContext(RunData data)
Return the Context needed by Velocity. |
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 org.apache.turbine.util.mail.HtmlEmail |
embed, getHtmlContent, setHtmlMsg, setHtmlMsg, setMsg, setTextMsg |
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 |
|
Field Detail |
private java.lang.String htmlTemplate
private java.lang.String textTemplate
private RunData data
private java.util.Hashtable embmap
Constructor Detail |
public VelocityHtmlEmail(RunData data) throws javax.mail.MessagingException
data
- A Turbine RunData object.MessagingException.
- Method Detail |
public VelocityHtmlEmail setHtmlTemplate(java.lang.String template)
template
- A String.public VelocityHtmlEmail setTextTemplate(java.lang.String template)
template
- A String.public void send() throws javax.mail.MessagingException
send
in class HtmlEmail
MessagingException.
- public java.lang.String embed(java.lang.String surl, java.lang.String name) throws javax.mail.MessagingException
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>
surl
- A String.name
- A String.MessagingException.
- embed.
public java.lang.String getCid(java.lang.String filename)
filename
- A String.embed.
private static final org.apache.velocity.context.Context getContext(RunData data)
data
- A Turbine RunData object.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |