Klasse VelocityHtmlEmail
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.
- Version:
- $Id$
- Autor:
- Eric Pugh, Andre Schild, Quinton McCombs, Henning P. Schmiedehausen, Peter Courcoux
-
Feldübersicht
Von Klasse geerbte Felder org.apache.commons.mail.HtmlEmail
CID_LENGTH, html, inlineEmbeds, inlineImages, text
Von Klasse geerbte Felder 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_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
-
Konstruktorübersicht
KonstruktorenKonstruktorBeschreibungConstructorVelocityHtmlEmail
(org.apache.velocity.context.Context context) Constructor, sets the context object. -
Methodenübersicht
Modifizierer und TypMethodeBeschreibungEmbed a file in the mail.Get the cid of an embedded file.Gets the host name of the outgoing mail server.send()
Actually send the mail.setHtmlTemplate
(String template) Set the HTML template for the mail.void
setMailServer
(String serverAddress) Sets the address of the outgoing mail server.setTextTemplate
(String template) Set the text template for the mail.Von Klasse geerbte Methoden org.apache.commons.mail.HtmlEmail
buildMimeMessage, embed, embed, embed, embed, embed, getHtml, getText, setHtmlMsg, setMsg, setTextMsg
Von Klasse geerbte Methoden org.apache.commons.mail.MultiPartEmail
addPart, addPart, addPart, attach, attach, attach, attach, attach, attach, attach, createBodyPart, createMimeMultipart, getContainer, getPrimaryBodyPart, getSubType, init, isBoolHasAttachments, isInitialized, setBoolHasAttachments, setInitialized, setSubType
Von Klasse geerbte Methoden org.apache.commons.mail.Email
addBcc, addBcc, addBcc, addBcc, addCc, addCc, addCc, addCc, addHeader, addReplyTo, addReplyTo, addReplyTo, addTo, addTo, addTo, addTo, createMimeMessage, getAuthenticator, getBccAddresses, getBounceAddress, getCcAddresses, getCharsetName, getContent, getContentType, getEmailBody, getFromAddress, getHeader, getHeaders, getHostName, getMailSession, getMessage, getMimeMessage, getPopHost, getPopPassword, getPopUserName, getReplyToAddresses, getSentDate, getSmtpPort, getSocketConnectionTimeout, getSocketTimeout, getSslSmtpPort, getSubject, getToAddresses, isDebug, isPopBeforeSmtp, isSendPartial, isSSL, isSSLCheckServerIdentity, isSSLOnConnect, isStartTLSEnabled, isStartTLSRequired, isTLS, sendMimeMessage, setAuthentication, setAuthenticator, setBcc, setBounceAddress, setCc, setCharset, setContent, setContent, setContent, setContentType, setDebug, setFrom, setFrom, setFrom, setFromAddress, setHeaders, setHostName, setMailSession, setMailSessionFromJNDI, setMessage, setPopBeforeSmtp, setPopBeforeSmtp, setPopHost, setPopPassword, setPopUsername, setReplyTo, setSendPartial, setSentDate, setSmtpPort, setSocketConnectionTimeout, setSocketConnectionTimeout, setSocketTimeout, setSocketTimeout, setSSL, setSSLCheckServerIdentity, setSSLOnConnect, setSslSmtpPort, setStartTLSEnabled, setStartTLSRequired, setSubject, setTLS, setTo, toInternetAddressArray, updateContentType
-
Konstruktordetails
-
VelocityHtmlEmail
public VelocityHtmlEmail()Constructor -
VelocityHtmlEmail
Constructor, sets the context object.- Parameter:
context
- A Velocity context object.
-
-
Methodendetails
-
setHtmlTemplate
Set the HTML template for the mail. This is the Velocity template to execute for the HTML part. Path is relative to the VM templates directory.- Parameter:
template
- A String.- Gibt zurück:
- A VelocityHtmlEmail (self).
-
setTextTemplate
Set the text template for the mail. This is the Velocity template to execute for the text part. Path is relative to the VM templates directory- Parameter:
template
- A String.- Gibt zurück:
- A VelocityHtmlEmail (self).
-
setMailServer
Sets the address of the outgoing mail server. This method should be used when you need to override the value stored in TR.props.- Parameter:
serverAddress
- host name of your outgoing mail server
-
getMailServer
Gets the host name of the outgoing mail server. If the server name has not been set by calling setMailServer(), the value from TR.props for mail.server will be returned. If TR.props has no value for mail.server, localhost will be returned.- Gibt zurück:
- host name of the mail server.
-
send
Actually send the mail.- Setzt außer Kraft:
send
in Klasseorg.apache.commons.mail.Email
- Löst aus:
org.apache.commons.mail.EmailException
- thrown if mail cannot be sent.
-
embed
Embed a file in the mail. The file can be referenced through its Content-ID. This function also registers the CID in an internal map, so the embedded file can be referenced more than once by using the getCid() function. This may be useful in a template.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>
- Setzt außer Kraft:
embed
in Klasseorg.apache.commons.mail.HtmlEmail
- Parameter:
surl
- A String.name
- A String.- Gibt zurück:
- A String with the cid of the embedded file.
- Siehe auch:
-
getCid
Get the cid of an embedded file.- Parameter:
filename
- A String.- Gibt zurück:
- A String with the cid of the embedded file.
- Siehe auch:
-