Reputation: 1118
This is my first time using the Gmail REST API and I'm trying to send an email using it. I followed the instructions on Google Developer site and got the authentication part successful. But now when I'm trying to send a email an Exception is thrown. Complete exception is,
Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/mail/util/MailLogger
at javax.mail.Session.initLogger(Session.java:227)
at javax.mail.Session.<init>(Session.java:212)
at javax.mail.Session.getDefaultInstance(Session.java:315)
at gmailconsole.Email.createEmail(Email.java:45)
at gmailconsole.GmailApiQuickStart.main(GmailApiQuickStart.java:91)
Caused by: java.lang.ClassNotFoundException: com.sun.mail.util.MailLogger
at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 5 more
The code that associated with the exception
public static void sendMessage(Gmail service, String userId, MimeMessage email)
throws MessagingException, IOException {
Message message = createMessageWithEmail(email);
message = service.users().messages().send(userId, message).execute();
System.out.println("Message id: " + message.getId());
System.out.println(message.toPrettyString());
}
Method call in the main class
try {
MimeMessage mimeMessage = Email.createEmail("[email protected]", "me", "Test", "This is a test message");
Email.sendMessage(service, "me", mimeMessage);
} catch (MessagingException ex) {
ex.printStackTrace();
}
P.S : I have added all the libraries and JavaEE API Library in NetBeasns
Upvotes: 0
Views: 927
Reputation: 3972
ClassNotFoundException
is definite: the class is not found in classpath
.
Short search reveals that the missing class com.sun.mail.util.MailLogger
is found in com.sun.mail_1.4.2.jar
; so have a look, I would place a bet that this would solve your problem.
Not the same problem, but it could be a nice information for you, too: java.lang.NoClassDefFoundError: javax/mail/Authenticator, whats wrong?
Upvotes: 1