Results 1 to 2 of 2
  1. #1
    kislay is offline Member
    Join Date
    Nov 2010
    Posts
    3
    Rep Power
    0

    Angry GlassFish Problem sending mail java.lang.SecurityException: Access to default session

    hi there, I need urgent help...
    I am trying to send mail using java mail api. I can send mail successfully when i do it using simple java but the moment i try doing it through my glassfish 3.0 app server i get java.lang.SecurityException: Access to default session denied
    I really frustrated please help as soon as possible. :confused: :mad:

  2. #2
    kislay is offline Member
    Join Date
    Nov 2010
    Posts
    3
    Rep Power
    0

    Default that's my code

    /*
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    */

    package com.kislay.vpd.mail;


    import java.util.logging.Level;
    import java.util.logging.Logger;
    import javax.annotation.Resource;
    import javax.mail.Message;

    import javax.mail.MessagingException;
    import javax.mail.Session;
    import javax.mail.Transport;
    import javax.mail.internet.InternetAddress;
    import javax.mail.internet.MimeMessage;

    /**
    *
    * @author root
    */
    public class UserAccountBSN {
    @Resource(name = "vpdmail")
    private Session mailSession;

    public void sendMessage() throws Exception {
    java.security.Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
    Message msg = new MimeMessage(mailSession);

    msg.setSubject("[app] Email Alert");
    msg.setRecipients(Message.RecipientType.TO,
    InternetAddress.parse("kislay@chromewebsolutions.c om"));
    msg.setText("Hello ");
    Transport.send(msg);
    System.out.println("message sent");


    }
    public static void main(String agrg[])
    {
    try {
    UserAccountBSN bsn = new UserAccountBSN();
    bsn.sendMessage();
    } catch (Exception ex) {
    Logger.getLogger(UserAccountBSN.class.getName()).l og(Level.SEVERE, null, ex);
    }
    }
    }


    jsp file for the same

    <%--
    Document : testmail
    Created on : Nov 17, 2010, 10:37:04 AM
    Author : root
    --%>

    <%@page import="com.kislay.vpd.mail.UserAccountBSN"%>
    <%@page contentType="text/html" pageEncoding="UTF-8"%>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">

    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>JSP Page</title>
    </head>
    <body>
    <h1>Hello World!</h1>
    <%
    try{
    UserAccountBSN bsn=new UserAccountBSN();
    bsn.sendMessage();
    }
    catch(Exception exc)
    {
    out.println(exc);
    }
    %>
    </body>
    </html>

Similar Threads

  1. Problem while sending a java mail
    By dushyant1244 in forum Advanced Java
    Replies: 15
    Last Post: 03-15-2013, 10:37 PM
  2. problem with sending mail usin javaX.mail api
    By sandeepsai39 in forum New To Java
    Replies: 4
    Last Post: 11-25-2009, 05:37 AM
  3. Problem in sending mail from java
    By npoorni in forum Advanced Java
    Replies: 1
    Last Post: 06-30-2009, 04:09 PM
  4. Facing problem while sending e-mail
    By jay8186 in forum Java Servlet
    Replies: 1
    Last Post: 03-25-2009, 07:34 AM
  5. Replies: 1
    Last Post: 03-10-2009, 01:12 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •