Я хочу отправить письмо через бланк, но я получаю
Статус HTTP 500? Внутренняя ошибка сервера
Исключение: javax.servlet.ServletException: выполнение сервлета вызвало исключение
org.apache.tomcat.websocket.server.WsFilter.doFilter (WsFilter.java:53)
Примечание: у меня установлены библиотеки: javax.mail.jar
и activation.jar
На моей Mail.jsp
странице
<form action="ServlateMail" method="post">
To:<input type="text" name="to" /><br/>
Subject:<input type="text" name="subject" /><br/>
Message:<input type="text" name="message" /><br/>
Your Email id:<input type="text" name="user" ><br/>
Password<;input type="password" name="pass" /><br/>
<input type="submit" value="send" />
</form>
По моему ServlateMail
:
package controller;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import utils.Sendmail;
public class ServletMail extends HttpServlet {
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse
response)
throws ServletException, IOException {
response.setContentType("text/html;charset-UTF-8");
PrintWriter out = response.getWriter();
String to = request.getParameter("to");
String subject = request.getParameter("subject");
String message = request.getParameter("message");
String user = request.getParameter("user");
String pass = request.getParameter("pass");
Sendmail.sendmailer(to,subject, message, user, pass);
System.out.println("Mail send successfully");
}
}
В моем классе Java:
package utils;
import java.io.*;
import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
public class Sendmail
{
public static void sendmailer(String to, String sub,
String msg, final String user,final String pass)
{
Properties props = new Properties();
props.put("mail.smtp.host", "smtp.gmail.com");
props.put("mail.smtp.port", "587");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.starttls.enable", "true");
Session session = Session.getInstance(props,new javax.mail.Authenticator()
{
protected PasswordAuthentication getPasswordAuthentication()
{
return new PasswordAuthentication(user,pass);
}
});
try
{
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(user));
message.addRecipient(Message.RecipientType.TO,new InternetAddress(to));
message.setSubject(sub);
System.out.print("testing");
message.setText(msg);
Transport.send(message);
}
catch(Exception e)
{
e.printStackTrace();
}
}
}