<%-- - Copyright (C) 2005 Jive Software. All rights reserved. - - This software is published under the terms of the GNU Public License (GPL), - a copy of which is included in this distribution. --%> <%@ page import="org.jivesoftware.util.*, org.jivesoftware.openfire.user.*, java.util.*, javax.mail.*, javax.mail.internet.*" errorPage="error.jsp" %> <%@ page import="java.text.SimpleDateFormat"%> <%@ page import="org.xmpp.packet.JID" %> <%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %> <%@ taglib uri="http://java.sun.com/jstl/fmt_rt" prefix="fmt" %> <%-- Define Administration Bean --%> <% webManager.init(request, response, session, application, out ); %> <% // Get paramters boolean doTest = request.getParameter("test") != null; boolean cancel = request.getParameter("cancel") != null; boolean sent = ParamUtils.getBooleanParameter(request, "sent"); boolean success = ParamUtils.getBooleanParameter(request, "success"); String from = ParamUtils.getParameter(request, "from"); String to = ParamUtils.getParameter(request, "to"); String subject = ParamUtils.getParameter(request, "subject"); String body = ParamUtils.getParameter(request, "body"); // Cancel if requested if (cancel) { response.sendRedirect("system-email.jsp"); return; } // Variable to hold messaging exception, if one occurs Exception mex = null; // Validate input Map errors = new HashMap(); if (doTest) { if (from == null) { errors.put("from", ""); } if (to == null) { errors.put("to", ""); } if (subject == null) { errors.put("subject", ""); } if (body == null) { errors.put("body", ""); } EmailService service = EmailService.getInstance(); // Validate host - at a minimum, it needs to be set: String host = service.getHost(); if (host == null) { errors.put("host", ""); } // if no errors, continue if (errors.size() == 0) { // Create a message MimeMessage message = service.createMimeMessage(); // Set the date of the message to be the current date SimpleDateFormat format = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss Z", java.util.Locale.US); format.setTimeZone(JiveGlobals.getTimeZone()); message.setHeader("Date", format.format(new Date())); // Set to and from. message.setRecipient(Message.RecipientType.TO, new InternetAddress(to, null)); message.setFrom(new InternetAddress(from, null)); message.setSubject(subject); message.setText(body); // Send the message, wrap in a try/catch: try { service.sendMessagesImmediately(Collections.singletonList(message)); // success, so indicate this: response.sendRedirect("system-emailtest.jsp?sent=true&success=true"); return; } catch (MessagingException me) { me.printStackTrace(); mex = me; } } } // Set var defaults Collection jids = webManager.getXMPPServer().getAdmins(); User user = null; if (!jids.isEmpty()) { for (JID jid : jids) { if (webManager.getXMPPServer().isLocal(jid)) { user = webManager.getUserManager().getUser(jid.getNode()); if (user.getEmail() != null) { break; } } } } if (from == null) { from = user.getEmail(); } if (to == null) { to = user.getEmail(); } if (subject == null) { subject = "Test email sent via Openfire"; } if (body == null) { body = "This is a test message."; } %> <fmt:message key="system.emailtest.title"/>

<% if (JiveGlobals.getProperty("mail.smtp.host") == null) { %>
"/>
<% } %> <% if (doTest || sent) { %> <% if (success) { %>
<% } else { %>
<% if (mex != null) { %> <% if (mex instanceof AuthenticationFailedException) { %> <% } else { %> (Message: <%= mex.getMessage() %>) <% } %> <% } %>
<% } %>
<% } %>
: <% String host = JiveGlobals.getProperty("mail.smtp.host"); if (host == null) { %> <% } else { %> <%= host %>:<%= JiveGlobals.getIntProperty("mail.smtp.port", 25) %> <% if (JiveGlobals.getBooleanProperty("mail.smtp.ssl", false)) { %> () <% } %> <% } %>
: <%= StringUtils.escapeHTMLTags(from) %> (Update Address)
: " size="40" maxlength="100">
: " size="40" maxlength="100">
:

"> ">