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 = "";
        String from = "";
        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[]) {
         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");

    * "send" method to send the message.
  public void send(String smtpServer, String to, String from
   , String subject, String body)
      Properties props = System.getProperties();
      // -- Attaching to default Session, or we could start a new one --
      props.put("", 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));
        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 --
      // -- Set some other header information --
      msg.setHeader("X-Mailer", "LOTONtechEmail");
      msg.setSentDate(new Date());
      // -- Send the message --
      System.out.println("Message sent OK.");
    catch (Exception ex)


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(
	at Method)
	at java.lang.ClassLoader.loadClass(
	at sun.misc.Launcher$AppClassLoader.loadClass(
	at java.lang.ClassLoader.loadClass(
	at view.Main.main(
Java Result: 1
BUILD SUCCESSFUL (total time: 14 seconds)


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

Servers via Netbeans ide :

Apache Tomcat7.0.11
GlassFish Server3.1

Libraries added to project class path:

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.