org.apache.turbine.util.webmacro
Class WebMacroEmail

java.lang.Object
  |
  +--org.apache.turbine.util.webmacro.WebMacroEmail

Deprecated. you should use velocity

public class WebMacroEmail
extends java.lang.Object

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.

Version:
$Id: WebMacroEmail.java,v 1.2 2002/07/11 16:53:19 mpoeschl Exp $
Author:
Jon S. Stevens

Constructor Summary
WebMacroEmail()
          Deprecated. Constructor
WebMacroEmail(org.webmacro.servlet.WebContext context)
          Deprecated. Constructor
 
Method Summary
 org.webmacro.servlet.WebContext getContext()
          Deprecated. Get the context object that will be merged with the template.
 void send()
          Deprecated. This method sends the email.
 WebMacroEmail setContext(org.webmacro.servlet.WebContext context)
          Deprecated. Set the context object that will be merged with the template.
 WebMacroEmail setFrom(java.lang.String from, java.lang.String email)
          Deprecated. From: name, email.
 WebMacroEmail setSubject(java.lang.String subject)
          Deprecated. Subject.
 WebMacroEmail setTemplate(java.lang.String template)
          Deprecated. Webmacro template to execute.
 WebMacroEmail setTo(java.lang.String to, java.lang.String email)
          Deprecated. To: name, email
 java.lang.String toString()
          Deprecated. The method toString() calls send() for ease of use within a WebMacro template (see example usage above).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

WebMacroEmail

public WebMacroEmail()
Deprecated. 
Constructor

WebMacroEmail

public WebMacroEmail(org.webmacro.servlet.WebContext context)
Deprecated. 
Constructor
Method Detail

setTo

public WebMacroEmail setTo(java.lang.String to,
                           java.lang.String email)
Deprecated. 
To: name, email
Parameters:
to - A String with the TO name.
email - A String with the TO email.
Returns:
A WebMacroEmail (self).

setFrom

public WebMacroEmail setFrom(java.lang.String from,
                             java.lang.String email)
Deprecated. 
From: name, email.
Parameters:
from - A String with the FROM name.
email - A String with the FROM email.
Returns:
A WebMacroEmail (self).

setSubject

public WebMacroEmail setSubject(java.lang.String subject)
Deprecated. 
Subject.
Parameters:
subject - A String with the subject.
Returns:
A WebMacroEmail (self).

setTemplate

public WebMacroEmail setTemplate(java.lang.String template)
Deprecated. 
Webmacro template to execute. Path is relative to the WM templates directory.
Parameters:
template - A String with the template.
Returns:
A WebMacroEmail (self).

setContext

public WebMacroEmail setContext(org.webmacro.servlet.WebContext context)
Deprecated. 
Set the context object that will be merged with the template.
Parameters:
context - A WebMacro context object.
Returns:
A WebMacroEmail (self).

getContext

public org.webmacro.servlet.WebContext getContext()
Deprecated. 
Get the context object that will be merged with the template.
Returns:
A WebContext (self).

send

public void send()
Deprecated. 
This method sends the email.

toString

public java.lang.String toString()
Deprecated. 
The method toString() calls send() for ease of use within a WebMacro template (see example usage above).
Overrides:
toString in class java.lang.Object
Returns:
An empty ("") String.


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