Class SMTPHandler
- All Implemented Interfaces:
Handler, TemplateInterface
- 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].error will contain the
error message.
There are 2 ways of using the sendmail template:
- <sendmail from=... to=... body=... subject=... />
- <sendmail from=... to=... body=... subject=... >
<param name=... value=... >
...
<param name=... value=... > </sendmail>
param tag adds an additional header
to the email message. There may be multiple headers of the same
name, 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 specify cc, bcc, or other
mail headers use param tags.
Note:
The to attribute, which is required,
specifies the actual recipients. When to is specified
as part of a param tag, 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:
- @(#)SMTPHandler.java 2.9
- Author:
- Stephen Uhler
-
Field Summary
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleandone(RewriteContext hr) If we run off the end of the page, but there is email pending to be sent, send it anyway.booleanInitializes the handler.booleaninit(RewriteContext hr) Called before this template processes any tags.booleanResponds to an HTTP request.static voidSend an email message via smtp - simple version.static voidsmtp(String fromHost, String smtpHost, String from, String to, String body, StringMap headers, Server server) voidAdd an additional email header.voidset-up an email message for sending.voidIf we haven't sent the mail yet - send it.
-
Constructor Details
-
SMTPHandler
public SMTPHandler()
-
-
Method Details
-
init
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
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:
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
Description copied from class:TemplateCalled before this template processes any tags.- Specified by:
initin interfaceTemplateInterface- Overrides:
initin classTemplate
-
tag_sendmail
set-up an email message for sending. If this is a singleton tag, then send the mail. -
tag_slash_sendmail
If we haven't sent the mail yet - send it. -
done
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
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(String fromHost, String smtpHost, String from, String to, String body, StringMap headers) throws IOException Send 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:
IOException
-
smtp
public static void smtp(String fromHost, String smtpHost, String from, String to, String body, StringMap headers, Server server) throws IOException - Throws:
IOException
-