|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.apache.turbine.util.webmacro.WebMacroEmail
This is a simple class for sending email from within WebMacro. Essentially, the body of the email is a WebMacro Context object. The beauty of this is that you can send email from within your WebMacro template or from your business logic in your Java code. The body of the email is just a WebMacro template so you can use all the template functionality of WebMacro within your emails!
Example Usage (This all needs to be on one line in your template):
Setup your context:
context.put ("WebMacroEmail", new WebMacroEmail() );
Then, in your template:
$WebMacroEmail.setTo("Jon Stevens", "jon@clearink.com") .setFrom("Mom", "mom@mom.com").setSubject("Eat dinner") .setTemplate("email/momEmail.wm") .setContext($context)The email/momEmail.wm template will then be parsed with the current Context that is stored in the RunData.getUser().getTemp(WebMacroService.WEBMACRO_CONTEXT) location. If the context does not already exist there, it will be created and then that will be used.
If you want to use this class from within your Java code all you have to do is something like this:
WebMacroEmail wme = new WebMacroEmail(); wme.setTo("Jon Stevens", "jon@clearink.com"); wme.setFrom("Mom", "mom@mom.com").setSubject("Eat dinner"); wme.setContext(context); wme.setTemplate("email/momEmail.wm") wme.send();(Note that when used within a WebMacro template, the send method will be called for you when WebMacro tries to convert the WebMacroEmail to a string by calling toString).
This class is just a wrapper around the SimpleEmail 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.
Field Summary | |
private org.webmacro.servlet.WebContext |
context
A WebContext |
private java.lang.String |
fromEmail
The from email field. |
private java.lang.String |
fromName
The from name field. |
private java.lang.String |
subject
The subject of the message. |
private java.lang.String |
template
The template to process, relative to WM's template directory. |
private java.lang.String |
toEmail
The to email field. |
private java.lang.String |
toName
The to name field. |
Constructor Summary | |
WebMacroEmail()
Constructor |
|
WebMacroEmail(org.webmacro.servlet.WebContext context)
Constructor |
Method Summary | |
org.webmacro.servlet.WebContext |
getContext()
Get the context object that will be merged with the template. |
void |
send()
This method sends the email. |
WebMacroEmail |
setContext(org.webmacro.servlet.WebContext context)
Set the context object that will be merged with the template. |
WebMacroEmail |
setFrom(java.lang.String from,
java.lang.String email)
From: name, email. |
WebMacroEmail |
setSubject(java.lang.String subject)
Subject. |
WebMacroEmail |
setTemplate(java.lang.String template)
Webmacro template to execute. |
WebMacroEmail |
setTo(java.lang.String to,
java.lang.String email)
To: name, email |
java.lang.String |
toString()
The method toString() calls send() for ease of use within a WebMacro template (see example usage above). |
Methods inherited from class java.lang.Object |
|
Field Detail |
private java.lang.String toName
private java.lang.String toEmail
private java.lang.String fromName
private java.lang.String fromEmail
private java.lang.String subject
private java.lang.String template
private org.webmacro.servlet.WebContext context
Constructor Detail |
public WebMacroEmail()
public WebMacroEmail(org.webmacro.servlet.WebContext context)
Method Detail |
public WebMacroEmail setTo(java.lang.String to, java.lang.String email)
to
- A String with the TO name.email
- A String with the TO email.public WebMacroEmail setFrom(java.lang.String from, java.lang.String email)
from
- A String with the FROM name.email
- A String with the FROM email.public WebMacroEmail setSubject(java.lang.String subject)
subject
- A String with the subject.public WebMacroEmail setTemplate(java.lang.String template)
template
- A String with the template.public WebMacroEmail setContext(org.webmacro.servlet.WebContext context)
context
- A WebMacro context object.public org.webmacro.servlet.WebContext getContext()
public void send()
public java.lang.String toString()
toString
in class java.lang.Object
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |