i tried this coding to send mail by using my aol mail account..but i got error
<%@page import ="java.sql.*" %>
<%@ page import="java.io.*,java.util.*,javax.mail.*"%>
<%@ page import="javax.mail.internet.*,javax.activation.*"%>
<%@ page import="javax.servlet.http.*,javax.servlet.*" %>
<%
String host="", user="", pass="";
host ="smtp.aol.com";
user="my mail id@aol.com";
pass="password";
String SSL_FACTORY = "javax.net.ssl.SSLSocketFactory";
String to ="receiver mail id@gmail.com";
String from ="my mail id@haol.com";
String subject ="hi how are you";
String messageText ="hi how are you";
boolean sessionDebug = true;
Properties props = System.getProperties();
props.put("mail.host", host);
props.put("mail.transport.protocol.", "smtp");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.", "true");
props.put("mail.smtp.port", "587");
props.put("mail.smtp.starttls.enable","true ");
props.put("mail.smtp.socketFactory.fallback", "false");
props.put("mail.smtp.socketFactory.class", SSL_FACTORY);
Session mailSession = Session.getDefaultInstance(props, null);
mailSession.setDebug(sessionDebug);
Message msg = new MimeMessage(mailSession);
msg.setFrom(new InternetAddress(from));
InternetAddress[] address = {new InternetAddress(to)};
msg.setRecipients(Message.RecipientType.TO, address);
msg.setSubject(subject);
msg.setContent(messageText, "text/html");
Transport transport = mailSession.getTransport("smtp");
transport.connect(host, user, pass);
transport.sendMessage(msg, msg.getAllRecipients());
out.print("<script>alert('Message Sent Successfully')</script>");
transport.close();
%>
but i got the following error..
type Exception report
message
descriptionThe server encountered an internal error () that prevented it from fulfilling this request.
exception
javax.servlet.ServletException: javax.mail.MessagingException: Could not connect to SMTP host: smtp.aol.com, port: 587;
nested exception is:
javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?
root cause
javax.mail.MessagingException: Could not connect to SMTP host: smtp.aol.com, port: 587;
nested exception is:
javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?
root cause
javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?
what port number should i use to resolve this problem..