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

Discussion in 'Java' started by sahm, Oct 18, 2011.

  1. sahm

    sahm Guest

    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.java:190)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
    ... 2 more
    Java Result: 1
    BUILD SUCCESSFUL (total time: 0 seconds)
    ==========================================

    I need your help

    Best
    Salim
     
    sahm, Oct 18, 2011
    #1
    1. Advertising

  2. sahm

    jlp Guest

    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.java:190)
    > at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
    > at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    > at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
    > ... 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)
     
    jlp, Oct 18, 2011
    #2
    1. Advertising

  3. sahm

    sahm Guest

    On Oct 18, 5:19 pm, jlp <> 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.java:190)
    > >    at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
    > >    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    > >    at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
    > >    ... 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
     
    sahm, Oct 19, 2011
    #3
  4. sahm

    Roedy Green Guest

    On Tue, 18 Oct 2011 03:12:39 -0700 (PDT), sahm <>
    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.
     
    Roedy Green, Oct 19, 2011
    #4
  5. sahm

    Arne Vajhøj Guest

    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
     
    Arne Vajhøj, Nov 6, 2011
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. pauli
    Replies:
    0
    Views:
    361
    pauli
    May 25, 2004
  2. radgey gadgey hl
    Replies:
    0
    Views:
    737
    radgey gadgey hl
    Nov 25, 2007
  3. Pierre Yves
    Replies:
    2
    Views:
    526
    Pierre Yves
    Jan 10, 2008
  4. Don Quijote de Nicaragua

    Error + Send Mail + ERROR: Failure sending mail.

    Don Quijote de Nicaragua, Jun 26, 2008, in forum: ASP .Net
    Replies:
    5
    Views:
    1,536
    Don Quijote de Nicaragua
    Jun 26, 2008
  5. Jake Barnes
    Replies:
    2
    Views:
    138
    Jake Barnes
    Apr 7, 2006
Loading...

Share This Page