List of usage examples for org.apache.commons.mail Email MAIL_HOST
String MAIL_HOST
To view the source code for org.apache.commons.mail Email MAIL_HOST.
Click Source Link
From source file:org.onehippo.forge.blog.components.Detail.java
/** * <p>Sends mail notification for newly added comment.</p> * <p>If component configuration for <code>receiver.email</code> is missing, no mails will be sent.</p> * @param commentBean {@link CommentBean} * @param request {@link HstRequest}//from w w w .ja va2 s . co m */ protected void sendNotificationMail(final CommentBean commentBean, final HstRequest request) { String mailhost = getParameter(Email.MAIL_HOST, request); String senderEmail = getParameter(Email.SENDER_EMAIL, request); String receiverEmail = getParameter(Email.RECEIVER_EMAIL, request); if (StringUtils.isBlank(mailhost)) { log.info("No value for mail.smtp.host in component configuration, trying localhost"); mailhost = LOCALHOST; } if (StringUtils.isBlank(senderEmail)) { log.info("No value for sender.email in component configuration, trying noreply@example.com"); senderEmail = DEFAULT_SENDER_MAIL; } if (StringUtils.isBlank(receiverEmail)) { log.warn( "No value for receiver.email in component configuration. Will not try to send mail notification."); return; } SimpleEmail email = new SimpleEmail(); StringBuffer subject = new StringBuffer("New comment: "); subject.append(commentBean.getTitle()); StringBuffer msg = new StringBuffer("The following comment has been added:\n"); msg.append(commentBean.getSummary()); email.setHostName(mailhost); try { email.addTo(receiverEmail); email.setFrom(senderEmail); email.setSubject(subject.toString()); email.setMsg(msg.toString()); email.send(); } catch (EmailException e) { log.error("Error sending notification for added comment", e); } }