Exception being thrown when using the Commons-email API

1

I'm trying to use the Commons-Email API as an alternative to known JavaMail to send emails in Java but there is a problem. The following Exception is being released:

  

Exception in thread "main" java.lang.NoClassDefFoundError:   javax / mail / Message at Main.main (Main.java:6)

The problem occurs on line 6 when I try to instantiate an object of class SimpleEmail . Here is my code:

import org.apache.commons.mail.SimpleEmail;

public class Main {
    public static void main(String[] args) {
        try {
            SimpleEmail email = new SimpleEmail(); // ops?! Aqui é lançada a Exception
            email.setHostName("mail.foo.com");

            email.setFrom("[email protected]", "rnxn") // remetente
                 .addTo("[email protected]", "Sr. Foo") // destinatário
                 .setMsg("Exception sendo lançada ao utilizar a API Commons-email") // corpo do email
                 .setSubject("StackOverflow"); // título

            email.send(); // envio

        } catch(Exception e){
            System.out.println(e.getMessage());
        } 
    }
}

I've successfully imported all of the .jar files that came in the download. Any solutions to the treatment of this problem?

    
asked by anonymous 06.11.2014 / 16:25

1 answer

1

The problem occurs because Commons-email is not an independent API as I thought, it is a more abstracted layer of JavaMail API , i.e. it has dependencies.

The exception thrown in my code is because it does not find the Message class, which belongs to JavaMail and is not included in the .jar files of commons .

To solve the problem, I just downloaded the JavaMail API by means of this link and make import her in the project along with Commons-email .

    
06.11.2014 / 16:51