1 Reply Latest reply: Feb 20, 2012 1:23 PM by bshannon RSS

    Setting properties to use local server Glassfish &Netbeans

    734840
      Hello. I have a Java Desktop App. I am trying to code to capture properties or db fields to send emails.

      Please find specs below.

      I do not have a internet connection right now I would like to understand how to setup my Glassfish Server3.1 provided in the Netbeans IDE.
      >
      Once you've installed the software, you need to get email account details to run the examples that follow. You'll need your ISP's SMTP (Simple Mail Transfer Protocol) server name and POP (Post Office Protocol) server name, your email account login name, and your mailbox password. Figure 1 shows my details -- not the real ones, you understand -- as used by Microsoft Outlook.



      Could someone view my code I have started and offer changes that could be made to send pretend emails from my Desktop App? and set them up
      using My local server Glassfish that shipped with netbeans?

      My Main will init the test classes:
      //java mail inserted
              String smtpServer = "model.mail.SimpleSender";
              String to = "cisumma@hotmail.com";
              String from = "cisumma@hotmail.com";
              String subject = "Hello Mail World subject";
              String body = "Hello Mail World body";
              SimpleSender ss = new SimpleSender();
              ss.send(smtpServer, to, from, subject, body);
              //java mail inserted
      Re-engineering class:
      /*
       * To change this template, choose Tools | Templates
       * and open the template in the editor.
       */
      package model.mail;
      
      /**
       *
       * @author Steves
       */
      import javax.mail.*;
      import javax.mail.internet.*;
      import java.util.*;
      /**
        * A simple email sender class.
        */
      public class SimpleSender
      {
        /**
          * Main method to send a message given on the command line.
          */
       /*
           *  public static void main(String args[]) {
          try
          {
            //THE ORIGINAL PROGRAM ARRAYS USED FOR COMMAND LINE 
               String smtpServer=args[0];
            String to=args[1];
            String from=args[2];
            String subject=args[3];
            String body=args[4];
            send(smtpServer, to, from, subject, body);
               
          }
                
          catch (Exception ex)
          {
            System.out.println("Usage: java com.lotontech.mail.SimpleSender"
             +" smtpServer toAddress fromAddress subjectText bodyText");
          }
          System.exit(0);
        }
      
           */
            /**
          * "send" method to send the message.
          */
        public void send(String smtpServer, String to, String from
         , String subject, String body)
        {
          try
          {
            Properties props = System.getProperties();
            // -- Attaching to default Session, or we could start a new one --
            props.put("mail.smtp.host", smtpServer);
            Session session = Session.getDefaultInstance(props, null);
            // -- Create a new message --
            Message msg = new MimeMessage(session);
            // -- Set the FROM and TO fields --
            msg.setFrom(new InternetAddress(from));
            msg.setRecipients(Message.RecipientType.TO,
              InternetAddress.parse(to, false));
            // -- We could include CC recipients too --
            // if (cc != null)
            // msg.setRecipients(Message.RecipientType.CC
            // ,InternetAddress.parse(cc, false));
            // -- Set the subject and body text --
            msg.setSubject(subject);
            msg.setText(body);
            // -- Set some other header information --
            msg.setHeader("X-Mailer", "LOTONtechEmail");
            msg.setSentDate(new Date());
            // -- Send the message --
            Transport.send(msg);
            System.out.println("Message sent OK.");
          }
          catch (Exception ex)
          {
            ex.printStackTrace();
          }
        }
      }
      error:
      Exception in thread "main" java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file javax/mail/Message
           at java.lang.ClassLoader.defineClass1(Native Method)
           at java.lang.ClassLoader.defineClass(ClassLoader.java:791)
           at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
           at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
           at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
           at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
           at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
           at java.security.AccessController.doPrivileged(Native Method)
           at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
           at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
           at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
           at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
           at view.Main.main(Main.java:142)
      Java Result: 1
      BUILD SUCCESSFUL (total time: 14 seconds)
      Specs

      I Do not have an internet connection I am trying to use the servers via netbeans (can not set up this).
      Ide=Netbeans


      Servers via Netbeans ide :

      Apache Tomcat7.0.11
      GlassFish Server3.1

      Libraries added to project class path:
      mail.jar
      mailapi.jar
      pop3.jar
      smtp.jar
      activation.jar