Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > I try to send e-mail for java but I get run time error

Reply
Thread Tools

I try to send e-mail for java but I get run time error

 
 
sahm
Guest
Posts: n/a
 
      10-18-2011
Hi Every One

I tried to send e-mail for java code using Apache Commends Mail
library 1.2
and below is my code
====================Start===================
package netscan;

import org.apache.commons.mail.SimpleEmail;
import org.apache.commons.mail.EmailException;
import org.apache.commons.mail.*;

/**
*
* @author salim
*/
public class SendMail {

public static void sendEmail()
{
System.out.println("Function is Colled");
try
{


SimpleEmail email = new SimpleEmail();
System.out.println("Email Opject is Created");
email.setHostName("mail.Hostname.com");
System.out.println("Host Name was Set");
//email.setAuthentication("my e-mail", "my Password");
email.setAuthenticator(new DefaultAuthenticator("my e-
mail","my password"));
email.setDebug(false);
//email.setDebug(true);
email.setSmtpPort(26);

email.addTo("receiver e-mail");

email.setFrom("my e-mail", "me");
email.setSubject("JAVA Test message");
email.setMsg("This is a simple test of commons-email");
email.send();

//return;
}
catch(EmailException ex)
{
System.out.println(ex.toString());
}
}

}
===================End====================

and there is no error in compaile time but in run time I get this
error

==========================================
Exception in thread "main" java.lang.NoClassDefFoundError: javax/mail/
Message
at netscan.SendMail.sendEmail(SendMail.java:31)
at netscan.NetScan.main(NetScan.java:104)
Caused by: java.lang.ClassNotFoundException: javax.mail.Message
at java.net.URLClassLoader$1.run(URLClassLoader.java: 202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.j ava:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:3 06)
at sun.misc.Launcher$AppClassLoader.loadClass(Launche r.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:2 47)
... 2 more
Java Result: 1
BUILD SUCCESSFUL (total time: 0 seconds)
==========================================

I need your help

Best
Salim
 
Reply With Quote
 
 
 
 
jlp
Guest
Posts: n/a
 
      10-18-2011
Le 18/10/2011 12:12, sahm a Úcrit :
> Hi Every One
>
> I tried to send e-mail for java code using Apache Commends Mail
> library 1.2
> and below is my code
> ====================Start===================
> package netscan;
>
> import org.apache.commons.mail.SimpleEmail;
> import org.apache.commons.mail.EmailException;
> import org.apache.commons.mail.*;
>
> /**
> *
> * @author salim
> */
> public class SendMail {
>
> public static void sendEmail()
> {
> System.out.println("Function is Colled");
> try
> {
>
>
> SimpleEmail email = new SimpleEmail();
> System.out.println("Email Opject is Created");
> email.setHostName("mail.Hostname.com");
> System.out.println("Host Name was Set");
> //email.setAuthentication("my e-mail", "my Password");
> email.setAuthenticator(new DefaultAuthenticator("my e-
> mail","my password"));
> email.setDebug(false);
> //email.setDebug(true);
> email.setSmtpPort(26);
>
> email.addTo("receiver e-mail");
>
> email.setFrom("my e-mail", "me");
> email.setSubject("JAVA Test message");
> email.setMsg("This is a simple test of commons-email");
> email.send();
>
> //return;
> }
> catch(EmailException ex)
> {
> System.out.println(ex.toString());
> }
> }
>
> }
> ===================End====================
>
> and there is no error in compaile time but in run time I get this
> error
>
> ==========================================
> Exception in thread "main" java.lang.NoClassDefFoundError: javax/mail/
> Message
> at netscan.SendMail.sendEmail(SendMail.java:31)
> at netscan.NetScan.main(NetScan.java:104)
> Caused by: java.lang.ClassNotFoundException: javax.mail.Message
> at java.net.URLClassLoader$1.run(URLClassLoader.java: 202)
> at java.security.AccessController.doPrivileged(Native Method)
> at java.net.URLClassLoader.findClass(URLClassLoader.j ava:190)
> at java.lang.ClassLoader.loadClass(ClassLoader.java:3 06)
> at sun.misc.Launcher$AppClassLoader.loadClass(Launche r.java:301)
> at java.lang.ClassLoader.loadClass(ClassLoader.java:2 47)
> ... 2 more
> Java Result: 1
> BUILD SUCCESSFUL (total time: 0 seconds)
> ==========================================
>
> I need your help
>
> Best
> Salim

the error is clear. It misses the import the javax.mail.* package (JEE
API)
 
Reply With Quote
 
 
 
 
sahm
Guest
Posts: n/a
 
      10-19-2011
On Oct 18, 5:19*pm, jlp <(E-Mail Removed)> wrote:
> Le 18/10/2011 12:12, sahm a Úcrit :
>
>
>
>
>
>
>
> > Hi Every One

>
> > I tried to send e-mail for java code using Apache Commends Mail
> > library *1.2
> > and below is my code
> > ====================Start===================
> > package netscan;

>
> > import org.apache.commons.mail.SimpleEmail;
> > import org.apache.commons.mail.EmailException;
> > import org.apache.commons.mail.*;

>
> > /**
> > * *
> > * * @author salim
> > * */
> > public class SendMail {

>
> > * * *public static void sendEmail()
> > * * *{
> > * * * * *System.out.println("Function is Colled");
> > * * * * *try
> > * * * * *{

>
> > * * * * *SimpleEmail email = new SimpleEmail();
> > * * * * *System.out.println("Email Opject is Created");
> > * * * * *email.setHostName("mail.Hostname.com");
> > * * * * *System.out.println("Host Name was Set");
> > * * * * *//email.setAuthentication("my e-mail", "my Password");
> > * * * * *email.setAuthenticator(new DefaultAuthenticator("my e-
> > mail","my password"));
> > * * * * *email.setDebug(false);
> > * * * * *//email.setDebug(true);
> > * * * * *email.setSmtpPort(26);

>
> > * * * * *email.addTo("receiver e-mail");

>
> > * * * * *email.setFrom("my e-mail", "me");
> > * * * * *email.setSubject("JAVA Test message");
> > * * * * *email.setMsg("This is a simple test of commons-email");
> > * * * * *email.send();

>
> > * * * * *//return;
> > * * * * *}
> > * * * * *catch(EmailException ex)
> > * * * * *{
> > * * * * * * *System.out.println(ex.toString());
> > * * * * *}
> > * * *}

>
> > }
> > ===================End====================

>
> > and there is no error in compaile time but in run time I get this
> > error

>
> > ==========================================
> > Exception in thread "main" java.lang.NoClassDefFoundError: javax/mail/
> > Message
> > * *at netscan.SendMail.sendEmail(SendMail.java:31)
> > * *at netscan.NetScan.main(NetScan.java:104)
> > Caused by: java.lang.ClassNotFoundException: javax.mail.Message
> > * *at java.net.URLClassLoader$1.run(URLClassLoader.java: 202)
> > * *at java.security.AccessController.doPrivileged(Native Method)
> > * *at java.net.URLClassLoader.findClass(URLClassLoader.j ava:190)
> > * *at java.lang.ClassLoader.loadClass(ClassLoader.java:3 06)
> > * *at sun.misc.Launcher$AppClassLoader.loadClass(Launche r.java:301)
> > * *at java.lang.ClassLoader.loadClass(ClassLoader.java:2 47)
> > * *... 2 more
> > Java Result: 1
> > BUILD SUCCESSFUL (total time: 0 seconds)
> > ==========================================

>
> > I need your help

>
> > Best
> > Salim

>
> the error is clear. It misses the import the javax.mail.* *package *(JEE
> API)


Hi
Thank you It working now
 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      10-19-2011
On Tue, 18 Oct 2011 03:12:39 -0700 (PDT), sahm <(E-Mail Removed)>
wrote, quoted or indirectly quoted someone who said :

>Exception in thread "main" java.lang.NoClassDefFoundError: javax/mail/

It looks as though Apache is just a wrapper for JavaMail. You must
install JavaMail by putting the jar in an ext directory. See
http://mindprod.com/jgloss/javamail.html
--
Roedy Green Canadian Mind Products
http://mindprod.com
It should not be considered an error when the user starts something
already started or stops something already stopped. This applies
to browsers, services, editors... It is inexcusable to
punish the user by requiring some elaborate sequence to atone,
e.g. open the task editor, find and kill some processes.

 
Reply With Quote
 
Arne Vajh°j
Guest
Posts: n/a
 
      11-06-2011
On 10/18/2011 10:19 AM, jlp wrote:
> Le 18/10/2011 12:12, sahm a Úcrit :
>> Exception in thread "main" java.lang.NoClassDefFoundError: javax/mail/
>> Message
>> at netscan.SendMail.sendEmail(SendMail.java:31)
>> at netscan.NetScan.main(NetScan.java:104)
>> Caused by: java.lang.ClassNotFoundException: javax.mail.Message
>> at java.net.URLClassLoader$1.run(URLClassLoader.java: 202)


> the error is clear. It misses the import the javax.mail.* package (JEE API)


It misses at least one class in javax.mail package that is used
in the code.

The import does not actually put any references in the class
file it only allows shorter names to be used in the source code.

Arne
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Run-time template list definition / Run-time variable type definition Pierre Yves C++ 2 01-10-2008 02:52 PM
can't get the text from a div, neither when I try to use innerHTML or when I try to walk the DOM Jake Barnes Javascript 2 04-07-2006 02:42 AM
MCP site error: "There was an error while registering you as a Learner. Please try after some time." BCW Microsoft Certification 1 12-02-2005 07:20 AM
Compiler error occurred when try to use a flexible template expression in preprocessor definesCompiler error occurred when try to use a flexible template expression in preprocessor defines snnn C++ 6 03-14-2005 04:09 PM
Try, Try, Try, again... Rick12N4@netscape.net Computer Support 3 01-29-2005 04:02 PM



Advertisments