|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.commons.mail.Email
org.apache.commons.mail.MultiPartEmail
org.apache.commons.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);
or
context.put("mail", myMail);VelocityHtmlEmail myEmail= new VelocityHtmlEmail(context);
context.put("mail", myMail);
The templates should be located under your Template turbine directory.
This class wraps the HtmlEmail class from commons-email. 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
You can turn on debugging for the JavaMail API by calling setDebug(true). The debugging messages will be written to System.out.
Field Summary |
Fields inherited from class org.apache.commons.mail.HtmlEmail |
CID_LENGTH, html, inlineImages, text |
Fields inherited from class org.apache.commons.mail.Email |
ATTACHMENTS, authenticator, bccList, bounceAddress, ccList, charset, content, CONTENT_TYPE, contentType, debug, EMAIL_BODY, EMAIL_SUBJECT, emailBody, FILE_SERVER, fromAddress, headers, hostName, ISO_8859_1, KOI8_R, MAIL_DEBUG, MAIL_HOST, MAIL_PORT, MAIL_SMTP_AUTH, MAIL_SMTP_FROM, MAIL_TRANSPORT_PROTOCOL, message, popBeforeSmtp, popHost, popPassword, popUsername, RECEIVER_EMAIL, RECEIVER_NAME, replyList, SENDER_EMAIL, SENDER_NAME, sentDate, SMTP, smtpPort, subject, TEXT_HTML, TEXT_PLAIN, toList, US_ASCII |
Constructor Summary | |
VelocityHtmlEmail(org.apache.velocity.context.Context context)
Constructor, sets the context object. |
|
VelocityHtmlEmail(RunData data)
Constructor, sets the context object from the passed 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. |
java.lang.String |
getMailServer()
Gets the host name of the outgoing mail server. |
java.lang.String |
send()
Actually send the mail. |
VelocityHtmlEmail |
setHtmlTemplate(java.lang.String template)
Set the HTML template for the mail. |
void |
setMailServer(java.lang.String serverAddress)
Sets the address of the outgoing mail server. |
VelocityHtmlEmail |
setTextTemplate(java.lang.String template)
Set the text template for the mail. |
Methods inherited from class org.apache.commons.mail.HtmlEmail |
buildMimeMessage, embed, setHtmlMsg, setMsg, setTextMsg |
Methods inherited from class org.apache.commons.mail.MultiPartEmail |
addPart, addPart, addPart, attach, attach, attach, attach, attach, createBodyPart, createMimeMultipart, getContainer, getPrimaryBodyPart, getSubType, init, isBoolHasAttachments, isInitialized, setBoolHasAttachments, setInitialized, setSubType |
Methods inherited from class org.apache.commons.mail.Email |
addBcc, addBcc, addCc, addCc, addHeader, addReplyTo, addReplyTo, addTo, addTo, getFromAddress, getHostName, getMailSession, getMimeMessage, getSentDate, getSmtpPort, getSubject, sendMimeMessage, setAuthentication, setAuthenticator, setBcc, setBounceAddress, setCc, setCharset, setContent, setContent, setDebug, setFrom, setFrom, setHeaders, setHostName, setMailSession, setPopBeforeSmtp, setSentDate, setSmtpPort, setSubject, setTo, toInternetAddressArray |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public VelocityHtmlEmail(RunData data)
data
- A Turbine RunData object.public VelocityHtmlEmail(org.apache.velocity.context.Context context)
context
- A Velocity context object.Method Detail |
public VelocityHtmlEmail setHtmlTemplate(java.lang.String template)
template
- A String.
public VelocityHtmlEmail setTextTemplate(java.lang.String template)
template
- A String.
public void setMailServer(java.lang.String serverAddress)
serverAddress
- host name of your outgoing mail serverpublic java.lang.String getMailServer()
public java.lang.String send() throws org.apache.commons.mail.EmailException
org.apache.commons.mail.EmailException
- thrown if mail cannot be sent.public java.lang.String embed(java.lang.String surl, java.lang.String name) throws VelocityEmailException
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.
VelocityEmailException
embed.
public java.lang.String getCid(java.lang.String filename)
filename
- A String.
embed.
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |