• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

javax/mail/MessagingException

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
I just installed java's sdk 1.4.2_04 and had a few problems getting the hello world sample to work even though I had set the Path variable correctly, got some advice that mentioned I should include the -cp switch before running sample and it did work. But I have downloaded Java's Mail API and the Jaf package required to enable the Mail API to work. I set the ClassPath correctly as the instruction guide instructed but when i tried running a test application it compiled correctly but did run, instead returned the following error.
Exception in thread "main" java.lang.NoClassDefFoundError: javax/mail/MessagingException.
Here is the code I was running
import javax.mail.*;
import java.util.Properties;
import javax.mail.internet.*;

public class Test {

public static void main(String[] args)
{
Properties props = new Properties();
//set mail server
props.put("mail.stmp.host","localhostgoeshere");
//create session
Session session = Session.getDefaultInstance(props,null);
//error throwing code
try
{
System.out.println("Create Mime");
MimeMessage message = new MimeMessage(session);
//fill in addressing info
message.setFrom(new InternetAddress("bob_burns@mail.com"));
System.out.println("Set From");
message.addRecipient(Message.RecipientType.TO,new InternetAddress("bob_burns@mail.com"));
message.setSubject("Testing Mail Merge");
message.setText("It works! Hello World");
//send message
System.out.println("Sending Mesage");
// Transport.send(message);
System.out.println("Message Sent!!");
}//end of try
catch(AddressException ae)
{
ae.printStackTrace();
}
catch(MessagingException me)
{
me.printStackTrace();
}//end of catch
}//end of main

}//end of class
Please help

compiles fine yet after running application in this way java -cp . Test. Exception occurs
 
Sheriff
Posts: 3341
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When you set the classpath on the command line, you need to set it to ALL the necessary packages. Setting it on the command line removes the system set classpath! The easiest thing to do is to ensure you systam classpath includes an entry for . allong with all needed packages and don't try setting it on the command line.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think you just write props.put("mail.smtp.host","localhostgoeshere"); instead of props.put("mail.stmp.host","localhostgoeshere");


In late
 
reply
    Bookmark Topic Watch Topic
  • New Topic