Solved

Sending an email from a java application

Posted on 2002-04-11
10
152 Views
Last Modified: 2013-11-24
However i am still having problems...


I am running on Windows XP, i have copied the "mail.jar" and the "activation.jar" files into the folder
C:\WINDOWS\java\classes directory, i downloaded them. I got them from the JavaMail API 1.2 release and the JAVABEANS ACTIVATION FRAMEWORK respectively.

I then added the classpath to them in my Visual J++. I specified the paths as:
C:\WINDOWS\java\classes\mail.jar
C:\WINDOWS\java\classes\activation.jar

but i get an Exception in thread "main" java.lang.NoClassDefFoundError: javax/mail/Message

I am really struggling to realise what i have done wrong...
can anyone spot any error?

Or does anyone have any code for sending an email. I have been trying all day, if you have a class that would work, aswell as the method call or constructor to the class...if so i will award you with the pints
0
Comment
Question by:BillFogarty
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
10 Comments
 
LVL 92

Expert Comment

by:objects
ID: 6935692
Not sure how the classpath works in J++.
In genberal though you should simply be able to put the jar files into your 'ext' directory(s) and they'll get picked up automatically.
Your ext directory(s) (you may have two one for jdk, and one for jre) will be in the JDK/JRE folder inside the lib folder.

0
 

Author Comment

by:BillFogarty
ID: 6935699
ya i have the mail.jar and activation.jar in both directories....
0
 
LVL 92

Expert Comment

by:objects
ID: 6935717
have you tried compiling/running from command line.
0
Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

 
LVL 2

Expert Comment

by:coreyit
ID: 6935787
objects touched on this, but I believe that you'll want to be sure that jar files are in lib, not classes.

-corey
0
 
LVL 92

Expert Comment

by:objects
ID: 6935825
> that jar files are in lib

They need to be in lib/ext, not lib.
0
 
LVL 2

Expert Comment

by:coreyit
ID: 6935842
Ah, true.
0
 
LVL 3

Expert Comment

by:msterjev
ID: 6936021
Add rt.jar (C:\Program Files\JavaSoft\JRE\1.3.1\lib\rt.jar)to the J++ classpath(also mail.jar and activation.jar from ext directory), and change the interpreter into the Options tab to be java.exe ( for example C:\jdk1.3.1\bin\java.exe).This would works!
0
 
LVL 1

Expert Comment

by:jose_tijo
ID: 6936036
Hi
  You have to put the jars (mail.jar & activation.jar) into the following directory

JAVA_HOME\jre\lib\ext\

Also following is the code to send email

You have to import the following

import javax.mail.*;
import javax.mail.event.*;
import javax.mail.internet.*;

/**Make Sure you are defining the variables correctly*/

/**Source Code*/

public static String sendMail() {
         Properties properties = new Properties();
         properties.put("mail.smtp.host", "<your smtp host>");
         properties.put("mail.from", "Sun Microystems");
         
         Session session = Session.getInstance(properties,null);
         
         try {
              Message message = new MimeMessage(session);
              int i=0;
              InternetAddress[] address = {new InternetAddress("<address here>")};
              message.setRecipients(Message.RecipientType.TO, address);
              message.setFrom(new InternetAddress("fromaddress@here.com"));
              message.setSubject("Hi");
              message.setContent(mail_Content, "text/html");
              transport = session.getTransport(address[0]);
                                       transport.connect();
                   transport.sendMessage(message,address);
                             }catch (Exception e) {
              System.out.println("Exception: " + e.toString());
              return "Error sending Mail";
          }
         return "Mail Successfully Send!";
    }


0
 
LVL 9

Expert Comment

by:Venci75
ID: 7940620
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:
PAQ'd and pts removed
Please leave any comments here within the next seven days.
 
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
 
Venci75
EE Cleanup Volunteer
0
 

Accepted Solution

by:
modulo earned 0 total points
ID: 7990802
Finalized as proposed

modulo

Community Support Moderator
Experts Exchange
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
Suggested Courses

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question