public class VelocityHtmlEmail extends org.apache.commons.mail.HtmlEmail
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.
CID_LENGTH, html, inlineEmbeds, inlineImages, text
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_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, message, popBeforeSmtp, popHost, popPassword, popUsername, RECEIVER_EMAIL, RECEIVER_NAME, replyList, SENDER_EMAIL, SENDER_NAME, sentDate, SMTP, smtpPort, socketConnectionTimeout, socketTimeout, ssl, sslSmtpPort, subject, TEXT_HTML, TEXT_PLAIN, tls, toList, US_ASCII
Constructor and Description |
---|
VelocityHtmlEmail()
Constructor
|
VelocityHtmlEmail(org.apache.velocity.context.Context context)
Constructor, sets the context object.
|
Modifier and Type | Method and Description |
---|---|
String |
embed(String surl,
String name)
Embed a file in the mail.
|
String |
getCid(String filename)
Get the cid of an embedded file.
|
String |
getMailServer()
Gets the host name of the outgoing mail server.
|
String |
send()
Actually send the mail.
|
VelocityHtmlEmail |
setHtmlTemplate(String template)
Set the HTML template for the mail.
|
void |
setMailServer(String serverAddress)
Sets the address of the outgoing mail server.
|
VelocityHtmlEmail |
setTextTemplate(String template)
Set the text template for the mail.
|
buildMimeMessage, embed, embed, embed, embed, embed, setHtmlMsg, setMsg, setTextMsg
addPart, addPart, addPart, attach, attach, attach, attach, attach, attach, createBodyPart, createMimeMultipart, getContainer, getPrimaryBodyPart, getSubType, init, isBoolHasAttachments, isInitialized, setBoolHasAttachments, setInitialized, setSubType
addBcc, addBcc, addBcc, addBcc, addCc, addCc, addCc, addCc, addHeader, addReplyTo, addReplyTo, addReplyTo, addTo, addTo, addTo, addTo, createMimeMessage, getBccAddresses, getBounceAddress, getCcAddresses, getFromAddress, getHeader, getHeaders, getHostName, getMailSession, getMimeMessage, getReplyToAddresses, getSentDate, getSmtpPort, getSocketConnectionTimeout, getSocketTimeout, getSslSmtpPort, getSubject, getToAddresses, isSendPartial, isSSL, isSSLCheckServerIdentity, isSSLOnConnect, isStartTLSEnabled, isStartTLSRequired, isTLS, sendMimeMessage, setAuthentication, setAuthenticator, setBcc, setBounceAddress, setCc, setCharset, setContent, setContent, setDebug, setFrom, setFrom, setFrom, setHeaders, setHostName, setMailSession, setMailSessionFromJNDI, setPopBeforeSmtp, setReplyTo, setSendPartial, setSentDate, setSmtpPort, setSocketConnectionTimeout, setSocketTimeout, setSSL, setSSLCheckServerIdentity, setSSLOnConnect, setSslSmtpPort, setStartTLSEnabled, setStartTLSRequired, setSubject, setTLS, setTo, toInternetAddressArray, updateContentType
public VelocityHtmlEmail()
public VelocityHtmlEmail(org.apache.velocity.context.Context context)
context
- A Velocity context object.public VelocityHtmlEmail setHtmlTemplate(String template)
template
- A String.public VelocityHtmlEmail setTextTemplate(String template)
template
- A String.public void setMailServer(String serverAddress)
serverAddress
- host name of your outgoing mail serverpublic String getMailServer()
public String send() throws org.apache.commons.mail.EmailException
send
in class org.apache.commons.mail.Email
org.apache.commons.mail.EmailException
- thrown if mail cannot be sent.public String embed(String surl, String name)
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>
embed
in class org.apache.commons.mail.HtmlEmail
surl
- A String.name
- A String.embed.
Copyright © 2000–2019 The Apache Software Foundation. All rights reserved.