UPDATE: The Code working when I use it as java program. And When I run it as jsp it gives the following exception. java.security.AccessControlException: access denied (java.security.SecurityPermission insertProvider.SunJSSE)
I posted the code below. I got the following exception.How to resolve this? I already searched in google but did not find the solution :( **java.security.AccessControlException:
<%@ page import="java.security.*" %>
<%@ page import="javax.mail.internet.*" %>
<%@ page import="javax.mail.*" %>
<%@ page import="java.util.*" %>
<%@ page import="java.io.*" %>
<html>
<body>
<%
String name=request.getParameter("name");
String from=request.getParameter("mail");
String message1=request.getParameter("msg");
try{
String toAddress="[email protected]";
String fromAddress=from;
String fromName=name;
String messageSubject="feedback";
String messageBody1=message1;
Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
Properties props=new Properties();
props.put("mail.smtp.host","smtp.gmail.com");
props.put("mail.debug","true");
props.put("mail.smtp.starttls.enable","true");
Session session1 = Session.getDefaultInstance(props,new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("[email protected]", "Password");
}
});
Message message=new MimeMessage(session1);
message.setFrom(new InternetAddress( fromAddress, fromName));
message.setRecipient(Message.RecipientType.TO,new InternetAddress( toAddress));
message.setSubject( messageSubject);
message.setText( messageBody1);
message.setSentDate(new Date());
Transport.send(message);
}
catch(Exception e)
{out.println(e);
}
%>
</body>
</html>
Help Me to fix this error