Class SMTPHandler
- java.lang.Object
-
- sunlabs.brazil.template.Template
-
- sunlabs.brazil.handler.SMTPHandler
-
- All Implemented Interfaces:
Handler,TemplateInterface
public class SMTPHandler extends Template implements Handler
Handler (or template) for Sending an email message via SMTP. The following server properties are used:- prefix, suffix, glob, match
- Specify the URL that triggers this handler.
(See
MatchString). - host
- The mail host (e.g. listening on the SMTP port). Defaults to "localhost".
Template to send an email message via SMTP.
The <sendmail> tag looks for the attributes:- to
- The message recipient(s) [required]
Recipients are be delimited by one or more
commas (,), spaces or tabs.
This is the actual destination list. If "To:" headers are
desired, they should be incorporated using
<param>tags (see below). - from
- The originator [required]
- body
- The text message [optional]
- subject
- The subject [optional]
[prefix].errorwill contain the error message.There are 2 ways of using the
sendmailtemplate:- <sendmail from=... to=... body=... subject=... />
- <sendmail from=... to=... body=... subject=... >
<param name=... value=... >
...
<param name=... value=... > </sendmail>
paramtag adds an additional header to the email message. There may be multiple headers of the samename, and their order is preserved.When a singleton tag is used, the
To:header is filled in to match the actual recipients. If you need to specifycc,bcc, or other mail headers useparamtags.Note:
Thetoattribute, which is required, specifies the actual recipients. Whentois specified as part of aparamtag, it is the recipient list presented to the email recipient, which may have nothing to do wih the actual recipients. In the singleton case, they are made the same.Send an email message based on the query data
Query parameters:
- to
- To address. Multible addresses should be delimited by spaces or commas.
- from
- From address
- message
- Message
- subject
- Subject
- Version:
- Author:
- Stephen Uhler
-
-
Constructor Summary
Constructors Constructor Description SMTPHandler()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleandone(RewriteContext hr)If we run off the end of the page, but there is email pending to be sent, send it anyway.booleaninit(Server server, java.lang.String prefix)Initializes the handler.booleaninit(RewriteContext hr)Called before this template processes any tags.booleanrespond(Request request)Responds to an HTTP request.static voidsmtp(java.lang.String fromHost, java.lang.String smtpHost, java.lang.String from, java.lang.String to, java.lang.String body, StringMap headers)Send an email message via smtp - simple version.static voidsmtp(java.lang.String fromHost, java.lang.String smtpHost, java.lang.String from, java.lang.String to, java.lang.String body, StringMap headers, Server server)voidtag_param(RewriteContext hr)Add an additional email header.voidtag_sendmail(RewriteContext hr)set-up an email message for sending.voidtag_slash_sendmail(RewriteContext hr)If we haven't sent the mail yet - send it.
-
-
-
Method Detail
-
init
public boolean init(Server server, java.lang.String prefix)
Description copied from interface:HandlerInitializes the handler.- Specified by:
initin interfaceHandler- Parameters:
server- The HTTP server that created thisHandler. TypicalHandlers will useServer.propsto obtain run-time configuration information.prefix- The handlers name. The string thisHandlermay prepend to all of the keys that it uses to extract configuration information fromServer.props. This is set (by theServerandChainHandler) to help avoid configuration parameter namespace collisions.- Returns:
trueif thisHandlerinitialized successfully,falseotherwise. Iffalseis returned, thisHandlershould not be used.
-
respond
public boolean respond(Request request) throws java.io.IOException
Description copied from interface:HandlerResponds to an HTTP request.- Specified by:
respondin interfaceHandler- Parameters:
request- TheRequestobject that represents the HTTP request.- Returns:
trueif the request was handled. A request was handled if a response was supplied to the client, typically by callingRequest.sendResponse()orRequest.sendError.- Throws:
java.io.IOException- if there was an I/O error while sending the response to the client. Typically, in that case, theServerwill (try to) send an error message to the client and then close the client's connection.The
IOExceptionshould not be used to silently ignore problems such as being unable to access some server-side resource (for example getting aFileNotFoundExceptiondue to not being able to open a file). In that case, theHandler's duty is to turn thatIOExceptioninto a HTTP response indicating, in this case, that a file could not be found.
-
init
public boolean init(RewriteContext hr)
Description copied from class:TemplateCalled before this template processes any tags.- Specified by:
initin interfaceTemplateInterface- Overrides:
initin classTemplate
-
tag_sendmail
public void tag_sendmail(RewriteContext hr)
set-up an email message for sending. If this is a singleton tag, then send the mail.
-
tag_slash_sendmail
public void tag_slash_sendmail(RewriteContext hr)
If we haven't sent the mail yet - send it.
-
done
public boolean done(RewriteContext hr)
If we run off the end of the page, but there is email pending to be sent, send it anyway.- Specified by:
donein interfaceTemplateInterface- Overrides:
donein classTemplate
-
tag_param
public void tag_param(RewriteContext hr)
Add an additional email header. Headers are added in the order in which they are processed. The special header "body" changes the body value instead.look for:
<param name="..." value="...>.Which will add the email header:name: value.The name "body" is special, and will cause the email body to be replaced.
-
smtp
public static void smtp(java.lang.String fromHost, java.lang.String smtpHost, java.lang.String from, java.lang.String to, java.lang.String body, StringMap headers) throws java.io.IOExceptionSend an email message via smtp - simple version.- Parameters:
fromHost- the hostname of the sender (may be null)smtpHost- the SMTP host (whose smtp daemon to contact)from- who the email is fromto- a space delimited list of recepientsbody- The message bodyheaders- message headers (may be null)- Throws:
java.io.IOException
-
-