0

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

1
  • java.security.AccessControlException: access denied (java.security.SecurityPermission insertProvider.SunJSSE) Dec 4, 2009 at 10:36

3 Answers 3

0

I don't think adding a security provider is required for sending mail. Also, using com.sun. classes is generally undesirable.

Here and here are ways to send mail using JavaMail.

But I recommend commons-mail.

6
  • If I remove the security provider I got following exception. I already checked that the links you give.That gives an exception related to tls property. I set that too.After that I got the same exception. java.lang.SecurityException: Access to default session denied Dec 4, 2009 at 10:47
  • is it possible to use commons-mail in jsp? I use SUn App server Dec 4, 2009 at 10:48
  • yes, it is. Although you seem to have a general security problem, rather than one with the mailing API.
    – Bozho
    Dec 4, 2009 at 10:50
  • Again When I am trying in different manner.. got this exception... java.security.AccessControlException: access denied (java.security.SecurityPermission insertProvider.SunJSSE) Dec 4, 2009 at 14:36
  • As I said, your problem is more generic and roots in the security settings of your application server. Check docs.sun.com/app/docs/doc/819-3664/abgjs?a=view
    – Bozho
    Dec 4, 2009 at 14:52
0

I'm sending mail using JavaMail via Gmail's smtp from my application and it works fine. I don't use any security provider, I simply add these properties to the message properties:

props.put("mail.smtp.starttls.enable","true"); 
props.put("mail.smtp.auth","true"); 
props.put("mail.mail.smtp.ssl.enable","true"); 

That's it. Mail is sent with no problem. Note however, that Gmail seems to want you to login into the webmail page every once in a while, or it will stop accepting your mail via smtp (I'm not sure 100% of this, it happened once to me).

0

When I am trying this snippnet in java it is working. When I am converting that in jsp with little modifications as shown in code it shows the exception

java.security.AccessControlException: access denied (java.security.SecurityPermission insertProvider.SunJSSE)

whether it is not possible to send email from jsp? this is the first time for me sending mail from jsp. I successfully run that program in java.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.