Search code examples
jakarta-mail

How to get rid of these exception DURING SENDING MAIL USING Gmail? I tried everything i got from Stack overflow


I have tried everything i got from internet but nothing worked. I am sending an email using mail API of java. But i am getting this exception while sending an email. Any idea ? How would i get rid of this? Thanks in advance. :)

----------------------------------- ERROR LOG ----------------------------------
        javax.servlet.ServletException: Servlet execution threw an exception
                    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
                root cause

                java.lang.NoClassDefFoundError: com/sun/mail/util/MailLogger
                    javax.mail.Session.initLogger(Session.java:227)
                    javax.mail.Session.<init>(Session.java:212)
                    javax.mail.Session.getInstance(Session.java:248)
                    controller.Send.doGet(Send.java:57)
                    javax.servlet.http.HttpServlet.service(HttpServlet.java:622)
                    javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
                    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) 


-------------------------------- Imported JARS-------------------------
javax.mail.jar


import java.util.Properties;

import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

Solution

  • Somewhere you have a mix of old and new JavaMail classes, or you have only a subset of the JavaMail classes. What is included in your application and what is included in Tomcat's lib directory?