Index: lams_admin/src/java/org/lamsfoundation/lams/admin/web/action/EmailUserAction.java =================================================================== diff -u -r9414a312296ddf8c3992a6207a2ce21cdb56c95f -r333022651b4f11aaa3c6943c900cdd6833b7cd8d --- lams_admin/src/java/org/lamsfoundation/lams/admin/web/action/EmailUserAction.java (.../EmailUserAction.java) (revision 9414a312296ddf8c3992a6207a2ce21cdb56c95f) +++ lams_admin/src/java/org/lamsfoundation/lams/admin/web/action/EmailUserAction.java (.../EmailUserAction.java) (revision 333022651b4f11aaa3c6943c900cdd6833b7cd8d) @@ -124,15 +124,24 @@ //String to = WebUtil.readStrParam(request, "to"); String subject = emailForm.getSubject(); - String body = emailForm.getBody(); + // strip HTML tags from body + String body = emailForm.getBody().replaceAll("
", "\n").replaceAll("\\<.*?\\>", ""); HttpSession ss1 = SessionManager.getSession(); UserDTO administrator = (UserDTO) ss1.getAttribute(AttributeNames.USER); - EmailUserAction.log.debug("Administrator " + administrator.getFirstName() + " " + administrator.getLastName() - + " sent email to user " + user.getFirstName() + " " + user.getLastName() + ": \n[subject] " + subject + "\n[message] " + body); + String to = user.getEmail(); + String toPerson = user.getFirstName() + " " + user.getLastName(); + + String from = administrator.getEmail(); + String fromPerson = administrator.getFirstName() + " " + administrator.getLastName(); + + + EmailUserAction.log.debug("Administrator " + fromPerson + " (" + from + ") " + + " sent email to user " + toPerson + "( " + to + ") " + ": \n[subject] " + subject + "\n[message] " + body); Properties properties = new Properties(); - Emailer.send(subject, user.getEmail(), administrator.getEmail(), body, properties); + + Emailer.send(subject, to, toPerson, from, fromPerson, body, properties); return mapping.findForward("usersearch"); } Index: lams_common/src/java/org/lamsfoundation/lams/events/DeliveryMethodMail.java =================================================================== diff -u -rb088ddf2b6f09504041d70812a6472eb8d59509d -r333022651b4f11aaa3c6943c900cdd6833b7cd8d --- lams_common/src/java/org/lamsfoundation/lams/events/DeliveryMethodMail.java (.../DeliveryMethodMail.java) (revision b088ddf2b6f09504041d70812a6472eb8d59509d) +++ lams_common/src/java/org/lamsfoundation/lams/events/DeliveryMethodMail.java (.../DeliveryMethodMail.java) (revision 333022651b4f11aaa3c6943c900cdd6833b7cd8d) @@ -1,5 +1,6 @@ package org.lamsfoundation.lams.events; +import java.io.UnsupportedEncodingException; import java.security.InvalidParameterException; import javax.mail.MessagingException; @@ -71,7 +72,7 @@ * if the operation failed */ public void sendFromSupportEmail(String subject, String to, String body) throws AddressException, - MessagingException { + MessagingException, UnsupportedEncodingException { Emailer.sendFromSupportEmail(subject, to, body); } @@ -87,7 +88,7 @@ * @throws MessagingException * if the operation failed */ - void notifyAdmin(String subject, String body) throws AddressException, MessagingException { + void notifyAdmin(String subject, String body) throws AddressException, MessagingException, UnsupportedEncodingException { String adminEmail = Configuration.get("LamsSupportEmail"); if (!StringUtils.isEmpty(adminEmail)) { sendFromSupportEmail(subject, adminEmail, body); Index: lams_common/src/java/org/lamsfoundation/lams/util/Emailer.java =================================================================== diff -u -r0efc922fa3f63f932af0a59395a506869e5318ce -r333022651b4f11aaa3c6943c900cdd6833b7cd8d --- lams_common/src/java/org/lamsfoundation/lams/util/Emailer.java (.../Emailer.java) (revision 0efc922fa3f63f932af0a59395a506869e5318ce) +++ lams_common/src/java/org/lamsfoundation/lams/util/Emailer.java (.../Emailer.java) (revision 333022651b4f11aaa3c6943c900cdd6833b7cd8d) @@ -1,5 +1,6 @@ package org.lamsfoundation.lams.util; +import java.io.UnsupportedEncodingException; import java.util.Properties; import javax.mail.Authenticator; @@ -22,83 +23,111 @@ */ public class Emailer { - public Emailer() { - } + public Emailer() { + } - /** - * Sends an email sourced from support email - * - * @param subject - * the subject of the email - * @param to - * the email of the recipient - * @param body - * the body of the email - */ - public static void sendFromSupportEmail(String subject, String to, String body) throws AddressException, - MessagingException { - String supportEmail = Configuration.get(ConfigurationKeys.LAMS_ADMIN_EMAIL); - Properties properties = new Properties(); - send(subject, to, supportEmail, body, properties); - } + /** + * Sends an email sourced from support email + * + * @param subject + * the subject of the email + * @param to + * the email of the recipient + * @param body + * the body of the email + */ + public static void sendFromSupportEmail(String subject, String to, String body) throws AddressException, + MessagingException, UnsupportedEncodingException { + String supportEmail = Configuration.get(ConfigurationKeys.LAMS_ADMIN_EMAIL); + Properties properties = new Properties(); + send(subject, to, supportEmail, body, properties); + } - /** - * Creates a mail session with authentication if it is required, ie if it - * has been set up with SMTP authentication in the config page - * - * @param properties - * @return - */ - public static Session getMailSession(Properties properties) { - Session session; - boolean useInternalSMTPServer = Boolean.parseBoolean(Configuration.get(ConfigurationKeys.USE_INTERNAL_SMTP_SERVER)); - if (! useInternalSMTPServer) { - String smtpServer = Configuration.get(ConfigurationKeys.SMTP_SERVER); - properties.put("mail.smtp.host", smtpServer); + /** + * Creates a mail session with authentication if it is required, ie if it + * has been set up with SMTP authentication in the config page + * + * @param properties + * @return + */ + public static Session getMailSession(Properties properties) { + Session session; + boolean useInternalSMTPServer = Boolean.parseBoolean(Configuration.get(ConfigurationKeys.USE_INTERNAL_SMTP_SERVER)); + if (! useInternalSMTPServer) { + String smtpServer = Configuration.get(ConfigurationKeys.SMTP_SERVER); + properties.put("mail.smtp.host", smtpServer); + } + + String smtpAuthUser = Configuration.get(ConfigurationKeys.SMTP_AUTH_USER); + String smtpAuthPass = Configuration.get(ConfigurationKeys.SMTP_AUTH_PASSWORD); + if (!useInternalSMTPServer && (smtpAuthUser != null) && !smtpAuthUser.trim().equals("")) { + properties.setProperty("mail.smtp.submitter", smtpAuthUser); + properties.setProperty("mail.smtp.auth", "true"); + SMTPAuthenticator auth = new SMTPAuthenticator(smtpAuthUser, smtpAuthPass); + session = Session.getInstance(properties, auth); + } else { + session = Session.getInstance(properties); + } + return session; } - - String smtpAuthUser = Configuration.get(ConfigurationKeys.SMTP_AUTH_USER); - String smtpAuthPass = Configuration.get(ConfigurationKeys.SMTP_AUTH_PASSWORD); - if (!useInternalSMTPServer && (smtpAuthUser != null) && !smtpAuthUser.trim().equals("")) { - properties.setProperty("mail.smtp.submitter", smtpAuthUser); - properties.setProperty("mail.smtp.auth", "true"); - SMTPAuthenticator auth = new SMTPAuthenticator(smtpAuthUser, smtpAuthPass); - session = Session.getInstance(properties, auth); - } else { - session = Session.getInstance(properties); + + /** + * Send email to recipients + * + * @param subject + * the subject of the email + * @param to + * the email of the recipient + * @param from + * the email to source the email from + * @param body + * the body of the email + */ + public static void send(String subject, String to, String from, String body, Properties mailServerConfig) + throws AddressException, MessagingException, UnsupportedEncodingException { + + send(subject, to, "", from, "", body, mailServerConfig); + + } - return session; - } - /** - * Send email to recipients - * - * @param subject - * the subject of the email - * @param to - * the email of the recipient - * @param from - * the email to source the email from - * @param body - * the body of the email - */ - public static void send(String subject, String to, String from, String body, Properties mailServerConfig) - throws AddressException, MessagingException { - Session session = getMailSession(mailServerConfig); - MimeMessage message = new MimeMessage(session); - message.setFrom(new InternetAddress(from)); - message.addRecipient(RecipientType.TO, new InternetAddress(to)); - message.setSubject(subject); - message.setText(body); + /** + * Send email to recipients + * + * @param subject + * the subject of the email + * @param to + * the email of the recipient + * @param toPerson + * receiver's name + * @param from + * the email to source the email from + * @param fromPerson + * sender's name + * @param body + * the body of the email + */ + public static void send(String subject, String to, String toPerson, String from, String fromPerson, String body, Properties mailServerConfig) + throws AddressException, MessagingException, UnsupportedEncodingException { + + Session session = getMailSession(mailServerConfig); + MimeMessage message = new MimeMessage(session); + + message.setFrom(new InternetAddress(from, fromPerson)); + message.addRecipient(RecipientType.TO, new InternetAddress(to, toPerson)); + message.setSubject(subject); + message.setText(body, "text/plain"); + + boolean useInternalSMTPServer = Boolean.parseBoolean(Configuration.get(ConfigurationKeys.USE_INTERNAL_SMTP_SERVER)); + if (useInternalSMTPServer) { + MailQue myMailQue = new MailQue(); + myMailQue.queMail(message); + } else { + Transport.send(message); + } + + } - boolean useInternalSMTPServer = Boolean.parseBoolean(Configuration.get(ConfigurationKeys.USE_INTERNAL_SMTP_SERVER)); - if (useInternalSMTPServer) { - MailQue myMailQue = new MailQue(); - myMailQue.queMail(message); - } else { - Transport.send(message); - } - } }