以下は、レストランのテーブルを予約するために使用するJSPコードです。テーブルの予約が成功したときにユーザーにメールを送信したいのですが、ユーザーにメールを送信できません。私はすでにそれを解決するために多くの方法を試しましたが、それはまた私に電子メールを送ることができないというエラーメッセージを返します。
<%@page import="java.util.Date"%>
<%@ page import="java.util.*" %>
<%@ page import="javax.mail.*" %>
<%@ page import="javax.mail.internet.*" %>
<%@ page import="javax.mail.internet.*,javax.activation.*"%>
<%@ page import="javax.servlet.http.*,javax.servlet.*" %>
<%@page import="java.text.SimpleDateFormat"%>
<%@page import="booking.Bean.Login"%>
<%@page import="booking.DB.OrderDB"%>
<%@page import="booking.Bean.Order"%>
<%@page import="booking.Wrapper.Wrapper"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<link href="css/style.css" rel="stylesheet" type="text/css">
<title>Add Order JSP</title>
</head>
<body>
<div id="container">
<div id="header">
<jsp:include page="header.jsp" />
</div>
<div id="menu">
<ul>
<li class="menuitem"><a href="aboutC.jsp">About</a>
</li>
<li class="menuitem"><a href="clientsC.jsp">Menu</a>
</li>
<li class="menuitem"><a href="contactC.jsp">Contact Us</a>
</li>
<li class="menuitem"><a href="login.jsp">Logout</a>
</li>
</ul>
</div>
<div id="leftmenu">
<div id="leftmenu_top"></div>
<div id="leftmenu_main">
<jsp:include page="orderMenu.jsp" />
</div>
<div id="leftmenu_bottom"></div>
</div>
<div id="content">
<div id="content_top"></div>
<div id="content_main">
<h2>Order Status</h2>
<%
String OrderCustId = request.getParameter("OrderCustIDtxt");
String OrderDate = request.getParameter("OrderDatetxt");
String OrderTime = request.getParameter("OrderTimetxt");
String OrderSeat = request.getParameter("OrderSeattxt");
//char BStatus = request.getParameter("OrderStatustxt");
//String userId = request.getParameter("txtUserId");
String custName = request.getParameter("textCustName");
String cEmail = request.getParameter("textCustEmail");
String cPhoneNo = request.getParameter("textCustContactNo");
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Date date = sdf.parse(OrderDate);
Order order = new Order();
order.getOrderId();
order.setCustId(OrderCustId);
order.setStaffId("2000");
order.setOrderDate(date);
order.setOrderTime(OrderTime);
order.setOrderSeat(OrderSeat);
order.setBStatus('A');
order.setOCustName(custName);
order.setcOEmail(cEmail);
order.setcOPhoneNo(cPhoneNo);
OrderDB orderDB = new OrderDB();
int seatAvaliable=orderDB.checkSeat(order);
if(seatAvaliable<35){
Wrapper wrapper = new Wrapper();
int status = wrapper.addOrder(order);
if (status > 0) {
out.print("<center><h5><font color='blue'>Successful Place Order</font></h5></center>");
%>
<br>
<table border="0" align="center">
<tr>
<th colspan="2" bgcolor="lightgrey">Display Details Added New
Order</th>
</tr>
<tr>
<td>Order ID:</td>
<td><%=order.getOrderId()%></td>
</tr>
<tr>
<td>Customer ID:</td>
<td><%=OrderCustId%></td>
</tr>
<tr>
<td>Order Date:</td>
<td><%=date%></td>
</tr>
<tr>
<td>Order Time:</td>
<td><%=OrderTime%></td>
</tr>
<tr>
<td>Order Seat:</td>
<td><%=OrderSeat%></td>
</tr>
<tr>
<td>Customer Name:</td>
<td><%=custName%></td>
</tr>
<tr>
<td>Customer Email:</td>
<td><%=cEmail%></td>
</tr>
<tr>
<td>Customer Contact No:</td>
<td><%=cPhoneNo%></td>
</tr>
<tr>
<td colspan="2"> </td>
</tr>
<tr>
<td></td>
<td><input type="button" value="Back"
onclick="history.go(-1)" /></td>
</tr>
</table>
<%
String result;
String to = cEmail; //ur client email
String from = "dasreg10@gmail.com"; //ur email address
String host = "smtp.gmail.com"; //for yahoo smtp.mail.yahoo.com == 465
Properties properties = System.getProperties();
properties.setProperty("mail.smtp.host", host);
properties.setProperty("mail.smtp.port","587");
Session mailSession = Session.getDefaultInstance(properties);
try{
MimeMessage message = new MimeMessage(mailSession);
message.setFrom(new InternetAddress(from));
message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
//This is your email subject
message.setSubject("L'eo Cafe Booking Success");
//This is the actual msg
message.setText(custName+" "+"Your table has been reserved at "+date+" "+OrderTime);
// Send message
Transport.send(message);
result = "Booking information sent successfully....";
}catch (MessagingException mex) {
mex.printStackTrace();
result = "Error: unable to send message....";
}
out.println("Result: " + result + "\n");
%>
<%
} else {
out.print("<center><h5><font color='red'>Failed to Place Order</font></h5></center>");
}
%>
<br>
<%
}
else{
out.print("<center><h5><font color='red'>Booking Full!!!</font></h5></center>");
}
%>
</div>
<div id="content_bottom"></div>
<jsp:include page="footer.jsp" />
</div>
</div>
</body>
</html>
以下は、システムから取得する例外です。
javax.mail.SendFailedException: Sending failed;
nested exception is:
class javax.mail.MessagingException: 530 5.7.0 Must issue a STARTTLS command first. ay5sm8087291pab.1
at javax.mail.Transport.send0(Transport.java:218)
at javax.mail.Transport.send(Transport.java:80)
at org.apache.jsp.addOrderJSP_jsp._jspService(addOrderJSP_jsp.java:256)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:929)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1002)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:585)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
これは私の最終年度の学術プロジェクトです。