0

I have a program that uses 2 Threads. These 2 threads work in cycle, meaning each thread waits for another thread to do the work than exits then another thread enter, do the work then exit. This happens over and over with a while loop.

On each thread I have an email sending code which uses Commons email classes. Everytime each thread reach the sending email code I get this Exception: NoClassDeFoundError com/sun/mail/util/PropUtil.

I don't understand because when I run the same email sending code on a deferent package the code execute perfectly.

I checked the answers from this question "How can I fix ClassNotFoundException: com.sun.mail.util.MailLogger?" But the answers are not satisfactory or related because I'm using Commons email and when I run the email code alone on a deferent package the code execute perfectly.

Here is the email sending code:

import org.apache.commons.mail.DefaultAuthenticator; 
import org.apache.commons.mail.Email;
import org.apache.commons.mail.SimpleEmail;
import org.apache.commons.mail.EmailException;

public class SimpleEmailSender {
     public static void main(String[] args) {

Email email = new SimpleEmail();

email.setHostName("smtp.gmail.com");
email.setSmtpPort(587);
email.setSSLOnConnect(true);
email.setAuthenticator(new DefaultAuthenticator(userName, password));

try {
email.setFrom("myemail@gmail.com");
email.setSubject("subject"); email.setMsg("message");
email.addTo("toemail@gmail.com");
email.send();
System.out.println("message sent Successfully");
   }
catch(EmailException e) {
System.out.println("error sending email");
e.printStackTrace();
   }

   }
}



rich25
  • 37
  • 11

0 Answers0