|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.commons.mail.Email org.apache.commons.mail.MultiPartEmail org.apache.commons.mail.HtmlEmail com.takaitra.util.VelocityEmail
public class VelocityEmail
Extends the HtmlEmail class from Apache Commons. Allows the content of the email to be easily created via the specified Velocity template and POJO.
These instructions work well in a J2EE environment. Feel free to tweak in order to fit your own needs.
resource.loader=class class.resource.loader.class=org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader
// Initialize the VelocityEmail object
VelocityEmail email = new VelocityEmail(templateName);
email.setHostName(smtphost);
email.setFrom(fromAddress);
email.setTo(toAddress);
// Merge a single javabean with the template. It will be referenced as in
// $bean.fieldname in your template.
email.setHtmlMsg(javabean)
// Alternatively, you may create your own VelocityContext to merge multiple
// javabeans with your template.
// VelocityContext context = new VelocityContext();
// context.put("bean1", javabean1);
// context.put("bean2", javabean2);
// email.setHtmlMsg(context);
// Send the email
email.send();
Field Summary |
---|
Fields inherited from class org.apache.commons.mail.HtmlEmail |
---|
CID_LENGTH |
Fields inherited from class org.apache.commons.mail.Email |
---|
ATTACHMENTS, CONTENT_TYPE, EMAIL_BODY, EMAIL_SUBJECT, FILE_SERVER, ISO_8859_1, KOI8_R, MAIL_DEBUG, MAIL_HOST, MAIL_PORT, MAIL_SMTP_AUTH, MAIL_SMTP_CONNECTIONTIMEOUT, MAIL_SMTP_FROM, MAIL_SMTP_PASSWORD, MAIL_SMTP_SOCKET_FACTORY_CLASS, MAIL_SMTP_SOCKET_FACTORY_FALLBACK, MAIL_SMTP_SOCKET_FACTORY_PORT, MAIL_SMTP_TIMEOUT, MAIL_SMTP_USER, MAIL_TRANSPORT_PROTOCOL, MAIL_TRANSPORT_TLS, RECEIVER_EMAIL, RECEIVER_NAME, SENDER_EMAIL, SENDER_NAME, SMTP, TEXT_HTML, TEXT_PLAIN, US_ASCII |
Constructor Summary | |
---|---|
VelocityEmail(java.lang.String templateFile)
The VelocityEmail constructor. |
Method Summary | |
---|---|
java.lang.String |
getTemplateFile()
Return the name of the Velocity template file |
void |
setHtmlMsg(java.lang.Object bean)
Set the HTML content of the email, merging the template file with the provided javabean. |
void |
setHtmlMsg(org.apache.velocity.VelocityContext context)
Set the HTML content of the email, merging the template file with the provided context. |
void |
setTemplateFile(java.lang.String templateFile)
Set the name of the Velocity template file |
void |
setTextMsg(java.lang.Object bean)
Set the text content of the email, merging the template file with the provided javabean. |
void |
setTextMsg(org.apache.velocity.VelocityContext context)
Set the text content of the email, merging the template file with the provided context. |
Methods inherited from class org.apache.commons.mail.HtmlEmail |
---|
buildMimeMessage, embed, embed, embed, embed, embed, embed, setHtmlMsg, setMsg, setTextMsg |
Methods inherited from class org.apache.commons.mail.MultiPartEmail |
---|
addPart, addPart, addPart, attach, attach, attach, attach, attach, getSubType, isBoolHasAttachments, setBoolHasAttachments, setSubType |
Methods inherited from class org.apache.commons.mail.Email |
---|
addBcc, addBcc, addBcc, addCc, addCc, addCc, addHeader, addReplyTo, addReplyTo, addReplyTo, addTo, addTo, addTo, getBccAddresses, getCcAddresses, getFromAddress, getHostName, getMailSession, getMimeMessage, getReplyToAddresses, getSentDate, getSmtpPort, getSocketConnectionTimeout, getSocketTimeout, getSslSmtpPort, getSubject, getToAddresses, isSSL, isTLS, send, sendMimeMessage, setAuthentication, setAuthenticator, setBcc, setBounceAddress, setCc, setCharset, setContent, setContent, setDebug, setFrom, setFrom, setFrom, setHeaders, setHostName, setMailSession, setMailSessionFromJNDI, setPopBeforeSmtp, setReplyTo, setSentDate, setSmtpPort, setSocketConnectionTimeout, setSocketTimeout, setSSL, setSslSmtpPort, setSubject, setTLS, setTo, updateContentType |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public VelocityEmail(java.lang.String templateFile)
templateFile
- the Velocity template file nameMethod Detail |
---|
public void setHtmlMsg(java.lang.Object bean) throws org.apache.commons.mail.EmailException
bean
- The javabean to be merged
org.apache.commons.mail.EmailException
public void setHtmlMsg(org.apache.velocity.VelocityContext context) throws org.apache.commons.mail.EmailException
context
- The Velocity context to be merged
org.apache.commons.mail.EmailException
public void setTextMsg(java.lang.Object bean) throws org.apache.commons.mail.EmailException
bean
- The javabean to be merged
org.apache.commons.mail.EmailException
public void setTextMsg(org.apache.velocity.VelocityContext context) throws org.apache.commons.mail.EmailException
context
- The Velocity context to be merged
org.apache.commons.mail.EmailException
public java.lang.String getTemplateFile()
public void setTemplateFile(java.lang.String templateFile)
templateFile
- the Velocity template file name
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |