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.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestMethod;
|
import org.springframework.web.bind.annotation.RequestMethod;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.validation.Valid;
|
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.
|
* Created by Olga on 7/20/2016.
|
||||||
@ -31,8 +36,50 @@ public class MailController {
|
|||||||
@Qualifier("templateSimpleMessage")
|
@Qualifier("templateSimpleMessage")
|
||||||
public SimpleMailMessage template;
|
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)
|
@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());
|
model.addAttribute("mailObject", new MailObject());
|
||||||
return "mail/send";
|
return "mail/send";
|
||||||
}
|
}
|
||||||
|
@ -17,5 +17,4 @@ spring.mail.properties.mail.smtp.starttls.enable=true
|
|||||||
#spring.mail.properties.mail.smtp.starttls.required=true
|
#spring.mail.properties.mail.smtp.starttls.required=true
|
||||||
|
|
||||||
# path to attachment file
|
# path to attachment file
|
||||||
attachment.invoice=path_to_file
|
attachment.invoice=path_to_file
|
||||||
#attachment.invoice=c:/invoice.jpg
|
|
@ -13,40 +13,44 @@
|
|||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div>
|
<div>
|
||||||
<h3>Create Email</h3>
|
<h3>${headerText}</h3>
|
||||||
<form:form method="POST" modelAttribute="mailObject">
|
<form:form method="POST" modelAttribute="mailObject" >
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<table cellspacing="0">
|
<div style="float:left;">
|
||||||
<tr>
|
<table cellspacing="0" width="300">
|
||||||
<th><label for="input_to">To</label></th>
|
<tr>
|
||||||
<td><form:input path="to" id="input_to" type="email"/>
|
<th><label for="input_to">To</label></th>
|
||||||
<small>Enter email address</small><br/>
|
<td><form:input path="to" id="input_to" type="email"/>
|
||||||
<form:errors path="to" cssStyle="color:red;font-size:small"/>
|
<small>Enter email address</small><br/>
|
||||||
</td>
|
<form:errors path="to" cssStyle="color:red;font-size:small"/>
|
||||||
</tr>
|
</td>
|
||||||
<tr>
|
</tr>
|
||||||
<th><label for="input_subject">Subject</label></th>
|
<tr>
|
||||||
<td><form:input path="subject" id="input_subject"/>
|
<th><label for="input_subject">Subject</label></th>
|
||||||
<small>Enter the subject</small><br/>
|
<td><form:input path="subject" id="input_subject"/>
|
||||||
<form:errors path="subject" cssStyle="color:red;font-size:small"/>
|
<small>Enter the subject</small><br/>
|
||||||
</td>
|
<form:errors path="subject" cssStyle="color:red;font-size:small"/>
|
||||||
</tr>
|
</td>
|
||||||
<tr>
|
</tr>
|
||||||
<th><label for="input_text">Message:</label></th>
|
<tr>
|
||||||
<td><form:textarea path="text"
|
<th><label for="input_text">${messageLabel}:</label></th>
|
||||||
rows="5" cols="50"
|
<td><form:textarea path="text"
|
||||||
id="input_text"/>
|
rows="5" cols="50"
|
||||||
<small>Enter message text</small><br/>
|
id="input_text"/>
|
||||||
<form:errors path="text" cssStyle="color:red;font-size:small"/>
|
<form:errors path="text" cssStyle="color:red;font-size:small"/>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th></th>
|
<th></th>
|
||||||
<td>
|
<td>
|
||||||
<input type="submit" value="Send">
|
<input type="submit" value="Send">
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
|
</div>
|
||||||
|
<div style="float:left; word-wrap: break-word; margin-left: 50px; width: 400px; color: grey">
|
||||||
|
${additionalInfo}
|
||||||
|
</div>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
</form:form>
|
</form:form>
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user