| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
package net.admin4j.util.notify; |
| 15 | |
|
| 16 | |
|
| 17 | |
import javax.servlet.FilterConfig; |
| 18 | |
import javax.servlet.ServletConfig; |
| 19 | |
import javax.servlet.ServletException; |
| 20 | |
|
| 21 | |
import net.admin4j.deps.commons.mail.HtmlEmail; |
| 22 | |
import net.admin4j.util.Admin4jRuntimeException; |
| 23 | |
import net.admin4j.util.HostUtils; |
| 24 | |
|
| 25 | |
|
| 26 | |
|
| 27 | |
|
| 28 | |
|
| 29 | |
|
| 30 | |
|
| 31 | |
|
| 32 | |
|
| 33 | |
|
| 34 | |
public class HtmlEmailNotifier extends BaseEmailNotifier { |
| 35 | |
|
| 36 | 27 | public HtmlEmailNotifier() {} |
| 37 | 0 | public HtmlEmailNotifier(FilterConfig config) throws ServletException { |
| 38 | 0 | configure(config); |
| 39 | 0 | } |
| 40 | |
|
| 41 | 0 | public HtmlEmailNotifier(ServletConfig config) throws ServletException { |
| 42 | 0 | configure(config); |
| 43 | 0 | } |
| 44 | |
|
| 45 | |
public void notify(String subject, String message) { |
| 46 | |
try { |
| 47 | |
|
| 48 | 3 | if (this.isSuppressEmail()) { |
| 49 | 0 | logger.debug("Email Notification surpressed: {}", message); |
| 50 | 0 | return; |
| 51 | |
} |
| 52 | |
HtmlEmail email = new HtmlEmail(); |
| 53 | |
email.setHostName(this.getMailServerHost()); |
| 54 | |
|
| 55 | 3 | if (message != null && message.indexOf("html") > 0) { |
| 56 | |
email.setHtmlMsg(message); |
| 57 | |
} |
| 58 | |
else email.setHtmlMsg("<html><body>" + message + "</body></html>"); |
| 59 | |
|
| 60 | |
|
| 61 | |
email.setDebug(logger.isDebugEnabled()); |
| 62 | |
|
| 63 | |
email.setSubject(subject); |
| 64 | |
email.setFrom(this.getFromEmailAddress()); |
| 65 | |
email.addTo(this.getToEmailAddress(), HostUtils.getHostName()); |
| 66 | |
email.send(); |
| 67 | 3 | } catch (Exception e) { |
| 68 | 3 | throw new Admin4jRuntimeException(e); |
| 69 | 0 | } |
| 70 | 0 | } |
| 71 | |
|
| 72 | |
public boolean supportsHtml() { |
| 73 | 3 | return true; |
| 74 | |
} |
| 75 | |
|
| 76 | |
|
| 77 | |
|
| 78 | |
public boolean supportsSMS() { |
| 79 | 3 | return false; |
| 80 | |
} |
| 81 | |
|
| 82 | |
} |