Implemented changes regarding the latest review.
This commit is contained in:
parent
4d46d52733
commit
807a4d2db9
|
@ -13,7 +13,12 @@ import org.springframework.web.bind.annotation.ModelAttribute;
|
|||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.validation.Valid;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Created by Olga on 7/20/2016.
|
||||
|
@ -31,8 +36,50 @@ public class MailController {
|
|||
@Qualifier("templateSimpleMessage")
|
||||
public SimpleMailMessage template;
|
||||
|
||||
private static final Map<String, Map<String, String>> labels;
|
||||
|
||||
static {
|
||||
labels = new HashMap<>();
|
||||
|
||||
//Simple email
|
||||
Map<String, String> props = new HashMap<>();
|
||||
props.put("headerText", "Send Simple Email");
|
||||
props.put("messageLabel", "Message");
|
||||
props.put("additionalInfo", "");
|
||||
labels.put("send", props);
|
||||
|
||||
//Email with template
|
||||
props = new HashMap<>();
|
||||
props.put("headerText", "Send Email Using Template");
|
||||
props.put("messageLabel", "Template Parameter");
|
||||
props.put("additionalInfo",
|
||||
"The parameter value will be added to the following message template:<br>" +
|
||||
"<b>This is the test email template for your email:<br>'Template Parameter'</b>"
|
||||
);
|
||||
labels.put("sendTemplate", props);
|
||||
|
||||
//Email with attachment
|
||||
props = new HashMap<>();
|
||||
props.put("headerText", "Send Email With Attachment");
|
||||
props.put("messageLabel", "Message");
|
||||
props.put("additionalInfo", "To make sure that you send an attachment with this email, change the value for the 'attachment.invoice' in the application.properties file to the path to the attachment.");
|
||||
labels.put("sendAttachment", props);
|
||||
}
|
||||
|
||||
@RequestMapping(value = {"/send", "/sendTemplate", "/sendAttachment"}, method = RequestMethod.GET)
|
||||
public String createMail(Model model) {
|
||||
public String createMail(Model model,
|
||||
HttpServletRequest request) {
|
||||
String action = request.getRequestURL().substring(
|
||||
request.getRequestURL().lastIndexOf("/") + 1
|
||||
);
|
||||
Map<String, String> props = labels.get(action);
|
||||
Set<String> keys = props.keySet();
|
||||
Iterator<String> iterator = keys.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
String key = iterator.next();
|
||||
model.addAttribute(key, props.get(key));
|
||||
}
|
||||
|
||||
model.addAttribute("mailObject", new MailObject());
|
||||
return "mail/send";
|
||||
}
|
||||
|
|
|
@ -17,5 +17,4 @@ spring.mail.properties.mail.smtp.starttls.enable=true
|
|||
#spring.mail.properties.mail.smtp.starttls.required=true
|
||||
|
||||
# path to attachment file
|
||||
attachment.invoice=path_to_file
|
||||
#attachment.invoice=c:/invoice.jpg
|
||||
attachment.invoice=path_to_file
|
|
@ -13,40 +13,44 @@
|
|||
</head>
|
||||
<body>
|
||||
<div>
|
||||
<h3>Create Email</h3>
|
||||
<form:form method="POST" modelAttribute="mailObject">
|
||||
<h3>${headerText}</h3>
|
||||
<form:form method="POST" modelAttribute="mailObject" >
|
||||
<fieldset>
|
||||
<table cellspacing="0">
|
||||
<tr>
|
||||
<th><label for="input_to">To</label></th>
|
||||
<td><form:input path="to" id="input_to" type="email"/>
|
||||
<small>Enter email address</small><br/>
|
||||
<form:errors path="to" cssStyle="color:red;font-size:small"/>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th><label for="input_subject">Subject</label></th>
|
||||
<td><form:input path="subject" id="input_subject"/>
|
||||
<small>Enter the subject</small><br/>
|
||||
<form:errors path="subject" cssStyle="color:red;font-size:small"/>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th><label for="input_text">Message:</label></th>
|
||||
<td><form:textarea path="text"
|
||||
rows="5" cols="50"
|
||||
id="input_text"/>
|
||||
<small>Enter message text</small><br/>
|
||||
<form:errors path="text" cssStyle="color:red;font-size:small"/>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th></th>
|
||||
<td>
|
||||
<input type="submit" value="Send">
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<div style="float:left;">
|
||||
<table cellspacing="0" width="300">
|
||||
<tr>
|
||||
<th><label for="input_to">To</label></th>
|
||||
<td><form:input path="to" id="input_to" type="email"/>
|
||||
<small>Enter email address</small><br/>
|
||||
<form:errors path="to" cssStyle="color:red;font-size:small"/>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th><label for="input_subject">Subject</label></th>
|
||||
<td><form:input path="subject" id="input_subject"/>
|
||||
<small>Enter the subject</small><br/>
|
||||
<form:errors path="subject" cssStyle="color:red;font-size:small"/>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th><label for="input_text">${messageLabel}:</label></th>
|
||||
<td><form:textarea path="text"
|
||||
rows="5" cols="50"
|
||||
id="input_text"/>
|
||||
<form:errors path="text" cssStyle="color:red;font-size:small"/>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th></th>
|
||||
<td>
|
||||
<input type="submit" value="Send">
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
<div style="float:left; word-wrap: break-word; margin-left: 50px; width: 400px; color: grey">
|
||||
${additionalInfo}
|
||||
</div>
|
||||
</fieldset>
|
||||
</form:form>
|
||||
</div>
|
||||
|
|
Loading…
Reference in New Issue