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 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 full Exception: Commons Email Exception

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();
}

}
}

Thank you

buraz
  • 19
  • 6
  • 1
    What do you use as a build system ? Any manager tool like maven or gradle, or are you simply running it in plain java commands ? In either case, can you add the build details as well ? What libraries are you using, what version of JDK is used, what is your classpath looks like ? Is this a code that runs as standalone or is it deployed inside a managed environment ? – alegria Sep 11 '22 at 12:36

0 Answers0