Set Up Email Alerts
Email alerts can be configured statically in conf
files to be sent at regular intervals throughout the lifecycle of an application. Use these steps to get up and running with the Alerting module:
-
Add this dependency to your
pom.xml
file:<dependency> <groupId>twigkit</groupId> <artifactId>twigkit.alert.runtime</artifactId> <version>${project.parent.version}</version> </dependency>
-
Set up
conf/alert/email/smtp.conf
; see below for an example configuration:# User to log into Appkit twigkit-user: foo twigkit-password: bar # User to send emails as from: foobar@twigkit.com password: foobar # Override to address for all config-based alerts to: reporting@some-alerting-domain.com # SMTP details mail.smtp.host: smtp.gmail.com mail.smtp.port: 587 mail.smtp.auth: true mail.smtp.starttls.enable: true
-
Set up
conf/alert/email/alerts/alerts.conf
; see below for an example configuration:email-template: http://localhost:8080/email/
-
Add the alert
.conf
files toconf/alert/email/alerts/my-alert-name-here.conf
; see below for an example:to: foobar@twigkit.com subject: New documents on brewing query: ?q=homebrew cron-expression: 30 * * * * ?
Here, the
cron-expression
defines how often to send the alert as described in this Quartz tutorial. -
Create a JSP, in this case configured as above, on a standard Appkit application would be in
src/main/webapp/WEB-INF/pages/email.jsp
and the content would include:<%@ page contentType="text/html" pageEncoding="UTF-8" %> <%@ include file="/WEB-INF/tags/client/taglibs.jspf" %> <search:localization var="resources" bundleName="resources" /> <search:twigkit> <search:platform conf="platforms.solr" /> <search:query var="query" parameters="*" /> <search:response var="response" platform="${platform}" query="${query}" /> </search:twigkit> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <h1>Automated alert for query ${query.value}</h1> <search:resultList response="${response}"> <search:result> <search:field name="title" /> <search:field name="description" /> </search:result> </search:resultList> </html>