Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

java.lang.SecurityException: Access to default session denied using jsp

843834Dec 13 2007 — edited Sep 13 2010
Is anythis wrong here help me
<%@ page import="java.security.Security,java.util.Properties,javax.mail.Message,javax.mail.PasswordAuthentication;
import javax.mail.Session,javax.mail.Transport,javax.mail.internet.InternetAddress,javax.mail.internet.MimeMessage" %>


<%try{
          String subject =request.getParameter("subject");
          String body =request.getParameter("body");
          String sender=request.getParameter("to");
          String recipients=request.getParameter("from");
             
                String mailhost = "smtp.gmail.com";
		Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
		 
		Properties props = new Properties();
		props.setProperty("mail.transport.protocol", "smtp");
		props.setProperty("mail.host", mailhost);
		props.put("mail.smtp.auth", "true");
		props.put("mail.smtp.port", "465");
		props.put("mail.smtp.socketFactory.port", "465");
		props.put("mail.smtp.socketFactory.class",
		"javax.net.ssl.SSLSocketFactory");
		props.put("mail.smtp.socketFactory.fallback", "false");
		props.setProperty("mail.smtp.quitwait", "false");

		Session sessions = Session.getDefaultInstance(props,
				new javax.mail.Authenticator() 
		{
			protected PasswordAuthentication getPasswordAuthentication()
			{ return new PasswordAuthentication("vanumasrikanth","******");	}
		});		
 
		javax.mail.internet.MimeMessage message = new MimeMessage(sessions);
		message.setSender(new InternetAddress(sender));
		message.setSubject(subject);
		message.setContent(body, "text/plain");
		if (recipients.indexOf(',') > 0) 
		message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(recipients));
		else
		message.setRecipient(Message.RecipientType.TO, new InternetAddress(recipients));
 
		
		Transport.send(message);
                out.print("mail sent");
              
           }
           catch (Exception e) {out.print(e);
           
           }

           
	
        
        %>
and the error is
java.lang.SecurityException: Access to default session denied
help me
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 11 2010
Added on Dec 13 2007
6 comments
6,396 views