cisumma 0 Newbie Poster

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.
Please find the example word doc attached that I am trying to engineer. JavaMail quick start.doc


I can not make heads or tails of how to set this up. I have planned on using Java mail.
The String variables in my main could not be right. That is most likely throwing the error
Thanks for your time.
Download the Java api here


I got my feet wet with the web app and servers etc 3 years ago so I do not remember anything on how to get started.

I did notice the example attached described settings for email accounts : 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.

The code I am learning from may be ancient. It would be awesome to see actual professionally written code to incorporate an email capability to a Desktop Application or
just an overview of how to design an advanced structure using properties and db tables as resources.

Could someone view my code I have started and offer changes that could be made to send pretend emails from my Desktop App?

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
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.