我已經離開這個頁面申請:如何從web應用程序發送電子郵件?
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%@taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<html>
<head>
<title> Application </title>
<link rel="stylesheet" href="CSS/Master.css">
</head>
<body> <!-- ----- <center> --->
<h2> Application Form </h2> <!-- -- --</center> ------>
<table>
<form:form method="POST" action="leaveapplyform.do" commandName="leaveapplyform" modelAttribute="leaveapplyform">
<tr> <td ><spring:message code="label.LeaveType"/> </td>
<td> <form:select path="LeaveType" name="LeaveType" id="choice" onchange="ShowReg(this.selectedIndex)">
<form:option value="Five Live Carry Forward"></form:option>
<form:option value="Live Carry Forward"></form:option>
<form:option value="Hello"></form:option></form:select> </td> </tr><br>
<tr> <td > <spring:message code="label.leavePeriod"/></td>
<td> <form:select path="leavePeriod" name="leavePeriod" id="choice" onchange="ShowReg(this.selectedIndex)">
<form:option value="fullDayPackage" >Full Day </form:option>
<form:option value="halfDayPackage">Half Day</form:option>
</form:select>
<br />
<div id="fullDay" style="display:none"><span class="style12"><spring:message code="label.selectHours"/></span>
<form:select path="selectHours" name="selectHours" id="selecte" onchange="ShowSkill(this.selectedIndex)">
<form:option selected="selected" value="event_one">1 HR</form:option>
<form:option value="event_two">2 HR</form:option>
<form:option value="event_three">3 HR </form:option>
<form:option value="event_four">4 HR</form:option>
<form:option value="event_five">5 HR </form:option>
</form:select>
</div>
<div id="halfDay" style="display:none">
</div>
</tr><br>
<tr> <td> <spring:message code="label.reason"/> <br /> </td> <td> <textarea rows="5" cols="22" name="reason"> </textarea> </td>
</tr>
<tr> <td><spring:message code="label.FirstApprover"/></td>
<td> <form:select path="FirstApprover" name="FirstApprover" >
<form:option value="zafar " >Zak </form:option>
<form:option value="priyanka">Ranka</form:option>
</form:select> </td> </tr>
<tr> <td><spring:message code="label.finalApprover"/></td>
<td> <form:select path="finalApprover" name="finalApprover" >
<form:option value="zafarm" >Zak </form:option>
<form:option value="priyanka">Ranka</form:option>
</form:select> </td> </tr>
<tr> <td colspan="2"> <br> </td> </tr>
<tr> <td > </td>
<td > <input type="reset"> <input type="submit" value="Submit" > </td> </tr>
<tr> <td colspan="2"> <br> </td> </tr> </form:form> </table>
<script type="text/javascript">
function ShowReg(op) {
document.getElementById('fullDay').style.display = 'none';
document.getElementById('halfDay').style.display = 'none';
if (op == 1) {
document.getElementById('fullDay').style.display = "block";
}
if (op == 2) {
document.getElementById('halfDay').style.display = "block";
}
}
function ShowSkill(op) {
document.getElementById('golf').style.display = 'none';
document.getElementById('other').style.display = 'none';
if (op == 1) {
document.getElementById('golf').style.display = "block";
}
if (op == 2) {
document.getElementById('other').style.display = "block";
}
}
</script>
<div id="other" style="display:none">
</div>
</body>
</html>
在提交,這就像休假類型原因,一些內容應包括電子郵件內容和的類,它是這樣的: @Service(「MailService的」) 公衆class ApplicationMailer { @ Autowired private MailSender mailSender;
@Autowired
private SimpleMailMessage preConfiguredMessage;
public void sendMail(String to, String subject, String body)
{
SimpleMailMessage message = new SimpleMailMessage();
message.setTo(to);
message.setSubject(subject);
message.setText(body);
mailSender.send(message);
}
public void sendPreConfiguredMail(String message)
{
public void apply(leaveapply leave) {
SimpleMailMessage msg = new SimpleMailMessage(this.templateMessage);
msg.setTo(order.getCustomer().getEmailAddress());
msg.setText(
"Dear " + order.getEmpName().getFirstName()
+ order.getCustomer().getLastName()
+ ", thank you);
try{
this.mailSender.send(msg);
}
catch(MailException ex) {
System.err.println(ex.getMessage());
}}}}
任何人都可以告訴我這將如何完成?
不要求教程。告訴我們你到目前爲止所嘗試過的。 – Tariq
Google仍在運行。你可以在網上找到很多例子。 – Konza
[從spring web應用程序發送電子郵件]的可能的重複(http://stackoverflow.com/questions/21754125/sending-an-e-mail-from-spring-web-application) – Mannekenpix