NIHVIVO-3118 Check whether site email is configured before trying to send email error message. Use FreemarkerEmailMessage method to get site reply to email address.
This commit is contained in:
parent
0e42232d3c
commit
8c13defa5a
3 changed files with 10 additions and 8 deletions
|
@ -47,7 +47,7 @@ public class ContactFormController extends FreemarkerHttpServlet {
|
|||
templateName = TEMPLATE_ERROR;
|
||||
}
|
||||
|
||||
else if (StringUtils.isEmpty(appBean.getContactMail())) {
|
||||
else if (StringUtils.isBlank(appBean.getContactMail())) {
|
||||
body.put("errorMessage",
|
||||
"The feedback form is currently disabled. In order to activate the form, a site administrator must provide a contact email address in the <a href='editForm?home=1&controller=ApplicationBean&id=1'>Site Configuration</a>");
|
||||
|
||||
|
@ -56,7 +56,6 @@ public class ContactFormController extends FreemarkerHttpServlet {
|
|||
|
||||
else {
|
||||
|
||||
String appName = appBean.getApplicationName();
|
||||
body.put("formAction", "submitFeedback");
|
||||
|
||||
if (vreq.getHeader("Referer") == null) {
|
||||
|
|
|
@ -15,6 +15,7 @@ import javax.servlet.ServletException;
|
|||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
|
@ -169,15 +170,13 @@ public class FreemarkerHttpServlet extends VitroHttpServlet {
|
|||
templateMap.put("adminErrorData", adminErrorData);
|
||||
|
||||
// Else send the data to the site administrator
|
||||
} else {
|
||||
} else if (FreemarkerEmailFactory.isConfigured(vreq)) {
|
||||
FreemarkerEmailMessage email = FreemarkerEmailFactory.createNewMessage(vreq);
|
||||
String recipient = ConfigurationProperties.getBean(getServletContext())
|
||||
.getProperty("email.replyTo");
|
||||
email.addRecipient(TO, recipient);
|
||||
email.addRecipient(TO, email.getReplyToAddress());
|
||||
email.setTemplate(Template.ERROR_EMAIL.toString());
|
||||
email.setBodyMap(adminErrorData);
|
||||
email.processTemplate();
|
||||
sentEmail = email.send();
|
||||
sentEmail = email.send();
|
||||
}
|
||||
|
||||
templateMap.put("sentEmail", sentEmail);
|
||||
|
|
|
@ -217,7 +217,11 @@ public class FreemarkerEmailMessage {
|
|||
bodyPart.setContent(textBody, type);
|
||||
content.addBodyPart(bodyPart);
|
||||
}
|
||||
|
||||
|
||||
public String getReplyToAddress() {
|
||||
return replyToAddress.getAddress();
|
||||
}
|
||||
|
||||
private <T> T nonNull(T value, T defaultValue) {
|
||||
return (value == null) ? defaultValue : value;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue