Results 1 to 2 of 2
  1. #1
    jazz2k8's Avatar
    jazz2k8 is offline Senior Member
    Join Date
    Apr 2008
    Posts
    150
    Rep Power
    7

    Thumbs up [SOLVED] Access to default session deniedAccess to default session denied

    <%@ page import="javax.mail.PasswordAuthentication,java.uti l.Date,java.util.Properties,javax.activation.DataH andler,javax.activation.FileDataSource,javax.mail. Message,javax.mail.MessagingException,javax.mail.M ultipart,javax.mail.Session,javax.mail.Transport,j avax.mail.internet.InternetAddress,javax.mail.inte rnet.MimeBodyPart,javax.mail.internet.MimeMessage, javax.mail.internet.MimeMultipart" %>



    <%
    String from = "abcd@gmail.com";
    String to[] = {"abcd@gmail.com"};
    String subject = "Password Recovery";
    String bodyText = "The information contained in this electronic message and any attachments to this message are intended for exclusive use of the addressee(s) and may contain confidential or privileged information. If you are not the intended recipient, please notify the sender at xyz@mycony.com immediately and destroy all copies of this message and any attachments. The views expressed in this E-mail message / Attachments, are those of the individual sender.";


    Properties props = new Properties();
    props.put("mail.smtp.host", "smtp.gmail.com");
    props.put("mail.smtp.auth", "true");
    props.put("mail.debug", "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");

    Session s = Session.getDefaultInstance(props,new javax.mail.Authenticator() {
    protected PasswordAuthentication getPasswordAuthentication() {
    return new PasswordAuthentication("abcd@gmail.com", "pwd1234");
    }
    });


    try {
    MimeMessage message = new MimeMessage(s);
    message.setFrom(new InternetAddress(from));
    for(int i=0;i<to.length;i++){
    message.setRecipient(Message.RecipientType.TO, new InternetAddress(to[i]));
    message.setSubject(subject);
    message.setSentDate(new Date());

    //
    // Set the email message text.
    //
    MimeBodyPart messagePart = new MimeBodyPart();
    messagePart.setText(bodyText);

    //
    // Set the email attachment file
    //
    /*MimeBodyPart attachmentPart = new MimeBodyPart();
    FileDataSource fileDataSource = new FileDataSource(filename) {
    @Override
    public String getContentType() {
    return "application/octet-stream";
    }
    };
    attachmentPart.setDataHandler(new DataHandler(fileDataSource));
    attachmentPart.setFileName(filename);*/

    Multipart multipart = new MimeMultipart();
    multipart.addBodyPart(messagePart);
    // multipart.addBodyPart(attachmentPart);

    message.setContent(multipart);

    Transport.send(message);
    }
    } catch (MessagingException e) {
    e.printStackTrace();
    }

    %>
    When i run this code first time it works perfect and 2nd time it gives error:
    Access to default session denied

    Thanks and Regards,
    ABB

  2. #2
    jazz2k8's Avatar
    jazz2k8 is offline Senior Member
    Join Date
    Apr 2008
    Posts
    150
    Rep Power
    7

    Default

    Issue Resolved..

    Resolution:

    Session s = Session.getDefaultInstance(props,new javax.mail.Authenticator() {
    Session s = Session.getInstance(props,new javax.mail.Authenticator() {

Similar Threads

  1. Access Remote Session Bean from an separate web app
    By kiyoharatakuya in forum Enterprise JavaBeans (EJB)
    Replies: 4
    Last Post: 04-24-2009, 03:46 PM
  2. Replies: 1
    Last Post: 04-21-2009, 11:20 PM
  3. Replies: 2
    Last Post: 12-23-2008, 06:35 PM
  4. want default value in ComboBox !!
    By Java.child in forum SWT / JFace
    Replies: 0
    Last Post: 09-29-2008, 09:57 PM
  5. Default Button
    By hiranya in forum AWT / Swing
    Replies: 2
    Last Post: 11-01-2007, 06:08 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
  •