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:
- Author:
- Stephen Uhler
-
Field Summary
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionboolean
done
(RewriteContext hr) If we run off the end of the page, but there is email pending to be sent, send it anyway.boolean
Initializes the handler.boolean
init
(RewriteContext hr) Called before this template processes any tags.boolean
Responds to an HTTP request.static void
Send an email message via smtp - simple version.static void
smtp
(String fromHost, String smtpHost, String from, String to, String body, StringMap headers, Server server) void
Add an additional email header.void
set-up an email message for sending.void
If we haven't sent the mail yet - send it.
-
Constructor Details
-
SMTPHandler
public SMTPHandler()
-
-
Method Details
-
init
Description copied from interface:Handler
Initializes the handler.- Specified by:
init
in interfaceHandler
- Parameters:
server
- The HTTP server that created thisHandler
. TypicalHandler
s will useServer.props
to obtain run-time configuration information.prefix
- The handlers name. The string thisHandler
may prepend to all of the keys that it uses to extract configuration information fromServer.props
. This is set (by theServer
andChainHandler
) to help avoid configuration parameter namespace collisions.- Returns:
true
if thisHandler
initialized successfully,false
otherwise. Iffalse
is returned, thisHandler
should not be used.
-
respond
Description copied from interface:Handler
Responds to an HTTP request.- Specified by:
respond
in interfaceHandler
- Parameters:
request
- TheRequest
object that represents the HTTP request.- Returns:
true
if 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, theServer
will (try to) send an error message to the client and then close the client's connection.The
IOException
should not be used to silently ignore problems such as being unable to access some server-side resource (for example getting aFileNotFoundException
due to not being able to open a file). In that case, theHandler
's duty is to turn thatIOException
into a HTTP response indicating, in this case, that a file could not be found.
-
init
Description copied from class:Template
Called before this template processes any tags.- Specified by:
init
in interfaceTemplateInterface
- Overrides:
init
in 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:
done
in interfaceTemplateInterface
- Overrides:
done
in 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
-