I’m trying to configure servlet to send a message to Gmail, but I’m getting waiting for reply message down my browser window.
Here’s the servlet code:
import javax.mail.*;
import javax.mail.internet.*;
import javax.servlet.http.*;
import javax.servlet.*;
import java.io.*;
public class JavaMailServlet extends HttpServlet
{
public void doGet(HttpServletRequest request,HttpServletResponse response)
{
try{
String userName=request.getParameter("p1");
String password=request.getParameter("p2");;
Properties props=new Properties();
props.put("mail.smtp.host","smtp.gmail.com");
props.put("mail.smtp.port",465);
Session ses=Session.getInstance(props,null);
Message msg=new MimeMessage(ses);
msg.setFrom(new InternetAddress(request.getRequestURI()));
msg.addRecipient(Message.RecipientType.TO,new InternetAddress("Boyofbackstreet@gmail.com"));
msg.setSubject("Hello");
msg.setText("What's up?");
Transport.send(msg);
response.getWriter().println("Message sent");
}
catch(Exception e)
{
System.out.println(e);
}
}
}
What do I’ve to do to make the connection?
Well, you haven’t set up any authentication as far as I can tell. You’ve grabbed the username and the password from the request (I do hope this is over HTTPS) but you haven’t used it anywhere.
I strongly recommend that you try to get this working in a console app which will be much easier to debug than a servlet, then put it into a servlet environment.