📄 velocityemail.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Frameset//EN""http://www.w3.org/TR/REC-html40/frameset.dtd"><!--NewPage--><HTML><HEAD><!-- Generated by javadoc on Fri Dec 06 19:57:10 CET 2002 --><TITLE>jakarta-turbine-2 2.2 API: Class VelocityEmail</TITLE><LINK REL ="stylesheet" TYPE="text/css" HREF="../../../../../stylesheet.css" TITLE="Style"></HEAD><BODY BGCOLOR="white"><!-- ========== START OF NAVBAR ========== --><A NAME="navbar_top"><!-- --></A><TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0"><TR><TD COLSPAN=2 BGCOLOR="#EEEEFF" CLASS="NavBarCell1"><A NAME="navbar_top_firstrow"><!-- --></A><TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3"> <TR ALIGN="center" VALIGN="top"> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../../overview-summary.html"><FONT CLASS="NavBarFont1"><B>Overview</B></FONT></A> </TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-summary.html"><FONT CLASS="NavBarFont1"><B>Package</B></FONT></A> </TD> <TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> <FONT CLASS="NavBarFont1Rev"><B>Class</B></FONT> </TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="class-use/VelocityEmail.html"><FONT CLASS="NavBarFont1"><B>Use</B></FONT></A> </TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-tree.html"><FONT CLASS="NavBarFont1"><B>Tree</B></FONT></A> </TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../../deprecated-list.html"><FONT CLASS="NavBarFont1"><B>Deprecated</B></FONT></A> </TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../../index-all.html"><FONT CLASS="NavBarFont1"><B>Index</B></FONT></A> </TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../../help-doc.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A> </TD> </TR></TABLE></TD><TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM></EM></TD></TR><TR><TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2"> <A HREF="../../../../../org/apache/turbine/util/velocity/VelocityActionEvent.html"><B>PREV CLASS</B></A> <A HREF="../../../../../org/apache/turbine/util/velocity/VelocityHtmlEmail.html"><B>NEXT CLASS</B></A></FONT></TD><TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2"> <A HREF="../../../../../index.html" TARGET="_top"><B>FRAMES</B></A> <A HREF="VelocityEmail.html" TARGET="_top"><B>NO FRAMES</B></A></FONT></TD></TR><TR><TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2"> SUMMARY: INNER | FIELD | <A HREF="#constructor_summary">CONSTR</A> | <A HREF="#method_summary">METHOD</A></FONT></TD><TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">DETAIL: FIELD | <A HREF="#constructor_detail">CONSTR</A> | <A HREF="#method_detail">METHOD</A></FONT></TD></TR></TABLE><!-- =========== END OF NAVBAR =========== --><HR><!-- ======== START OF CLASS DATA ======== --><H2><FONT SIZE="-1">org.apache.turbine.util.velocity</FONT><BR>Class VelocityEmail</H2><PRE>java.lang.Object | +--<B>org.apache.turbine.util.velocity.VelocityEmail</B></PRE><HR><DL><DT>public class <B>VelocityEmail</B><DT>extends java.lang.Object</DL><P>This is a simple class for sending email from within Velocity. Essentially, the body of the email is processed with a Velocity Context object. 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! <p>Example Usage (This all needs to be on one line in your template): <p>Setup your context: <p>context.put ("VelocityEmail", new VelocityEmail() ); <p>Then, in your template: <pre> $VelocityEmail.setTo("Jon Stevens", "jon@latchkey.com") .setFrom("Mom", "mom@mom.com").setSubject("Eat dinner") .setTemplate("email/momEmail.vm") .setContext($context) </pre> The email/momEmail.wm template will then be parsed with the Context that was defined with setContext(). <p>If you want to use this class from within your Java code all you have to do is something like this: <pre> VelocityEmail ve = new VelocityEmail(); ve.setTo("Jon Stevens", "jon@latchkey.com"); ve.setFrom("Mom", "mom@mom.com").setSubject("Eat dinner"); ve.setContext(context); ve.setTemplate("email/momEmail.vm") ve.send(); </pre> <p>(Note that when used within a Velocity template, the send method will be called for you when Velocity tries to convert the VelocityEmail to a string by calling toString()).</p> <p>If you need your email to be word-wrapped, you can add the following call to those above: <pre> ve.setWordWrap (60); </pre> <p>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 TurbineConfig class for more information.</p><P><DL><DT><B>Version: </B><DD>$Id: VelocityEmail.java,v 1.2 2002/07/11 16:53:19 mpoeschl Exp $</DD><DT><B>Author: </B><DD><a href="mailto:jon@latchkey.com">Jon S. Stevens</a>, <a href="mailto:gcoladonato@yahoo.com">Greg Coladonato</a></DD></DL><HR><P><!-- ======== INNER CLASS SUMMARY ======== --><!-- =========== FIELD SUMMARY =========== --><!-- ======== CONSTRUCTOR SUMMARY ======== --><A NAME="constructor_summary"><!-- --></A><TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%"><TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor"><TD COLSPAN=2><FONT SIZE="+2"><B>Constructor Summary</B></FONT></TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD><CODE><B><A HREF="../../../../../org/apache/turbine/util/velocity/VelocityEmail.html#VelocityEmail()">VelocityEmail</A></B>()</CODE><BR> Constructor</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD><CODE><B><A HREF="../../../../../org/apache/turbine/util/velocity/VelocityEmail.html#VelocityEmail(org.apache.velocity.context.Context)">VelocityEmail</A></B>(org.apache.velocity.context.Context context)</CODE><BR> Constructor</TD></TR></TABLE> <!-- ========== METHOD SUMMARY =========== --><A NAME="method_summary"><!-- --></A><TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%"><TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor"><TD COLSPAN=2><FONT SIZE="+2"><B>Method Summary</B></FONT></TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE> org.apache.velocity.context.Context</CODE></FONT></TD><TD><CODE><B><A HREF="../../../../../org/apache/turbine/util/velocity/VelocityEmail.html#getContext()">getContext</A></B>()</CODE><BR> Get the context object that will be merged with the template.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE> void</CODE></FONT></TD><TD><CODE><B><A HREF="../../../../../org/apache/turbine/util/velocity/VelocityEmail.html#send()">send</A></B>()</CODE><BR> This method sends the email.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE> <A HREF="../../../../../org/apache/turbine/util/velocity/VelocityEmail.html">VelocityEmail</A></CODE></FONT></TD><TD><CODE><B><A HREF="../../../../../org/apache/turbine/util/velocity/VelocityEmail.html#setContext(org.apache.velocity.context.Context)">setContext</A></B>(org.apache.velocity.context.Context context)</CODE><BR> Set the context object that will be merged with the template.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE> <A HREF="../../../../../org/apache/turbine/util/velocity/VelocityEmail.html">VelocityEmail</A></CODE></FONT></TD><TD><CODE><B><A HREF="../../../../../org/apache/turbine/util/velocity/VelocityEmail.html#setFrom(java.lang.String, java.lang.String)">setFrom</A></B>(java.lang.String from, java.lang.String email)</CODE><BR> From: name, email.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE> <A HREF="../../../../../org/apache/turbine/util/velocity/VelocityEmail.html">VelocityEmail</A></CODE></FONT></TD><TD><CODE><B><A HREF="../../../../../org/apache/turbine/util/velocity/VelocityEmail.html#setSubject(java.lang.String)">setSubject</A></B>(java.lang.String subject)</CODE><BR> Subject.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE> <A HREF="../../../../../org/apache/turbine/util/velocity/VelocityEmail.html">VelocityEmail</A></CODE></FONT></TD><TD><CODE><B><A HREF="../../../../../org/apache/turbine/util/velocity/VelocityEmail.html#setTemplate(java.lang.String)">setTemplate</A></B>(java.lang.String template)</CODE><BR> Velocity template to execute.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE> <A HREF="../../../../../org/apache/turbine/util/velocity/VelocityEmail.html">VelocityEmail</A></CODE></FONT></TD><TD><CODE><B><A HREF="../../../../../org/apache/turbine/util/velocity/VelocityEmail.html#setTo(java.lang.String, java.lang.String)">setTo</A></B>(java.lang.String to, java.lang.String email)</CODE><BR>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -