M
Mikey
I am attempting to use JavaMail to send an email from a servlet running
under Tomcat. The code compiles fine but the servlet processing stops
on an attempt to create a session instance. I'm new to Java and am
probably making a basic mistake. The code segments are shown below. The
processing stops at the "Session.." line with the Tomcat root cause
error message:
"java.lang.NoClassDefFoundError: javax/mail/Session"
I've tried several variations of examples that I've found in Java
references - with no luck.
Any help would be appreciated.
Thanks
-------------------------------------------
Code snippets:
import java.io.*;
import java.util.*;
import java.text.*;
import javax.mail.*;
import javax.mail.internet.*;
import java.util.Properties;
........
Properties props = new Properties();
props.setProperty("mail.transport.protocol", "smtp");
props.setProperty("mail.host", "host mail server");
props.setProperty("mail.user", "sender email");
props.setProperty("mail.password", "my password");
Session mailSession = Session.getDefaultInstance(props, null);
try {
Transport transport = mailSession.getTransport();
MimeMessage message = new MimeMessage(mailSession);
message.setContent("This is a test", "text/plain");
message.addRecipient(Message.RecipientType.TO,
new InternetAddress("(e-mail address removed)"));
transport.connect();
transport.sendMessage(message,
message.getRecipients(Message.RecipientType.TO));
transport.close();
} catch (MessagingException ex) {
while ((ex = (MessagingException)ex.getNextException()) != null) {
ex.printStackTrace();
}
}
under Tomcat. The code compiles fine but the servlet processing stops
on an attempt to create a session instance. I'm new to Java and am
probably making a basic mistake. The code segments are shown below. The
processing stops at the "Session.." line with the Tomcat root cause
error message:
"java.lang.NoClassDefFoundError: javax/mail/Session"
I've tried several variations of examples that I've found in Java
references - with no luck.
Any help would be appreciated.
Thanks
-------------------------------------------
Code snippets:
import java.io.*;
import java.util.*;
import java.text.*;
import javax.mail.*;
import javax.mail.internet.*;
import java.util.Properties;
........
Properties props = new Properties();
props.setProperty("mail.transport.protocol", "smtp");
props.setProperty("mail.host", "host mail server");
props.setProperty("mail.user", "sender email");
props.setProperty("mail.password", "my password");
Session mailSession = Session.getDefaultInstance(props, null);
try {
Transport transport = mailSession.getTransport();
MimeMessage message = new MimeMessage(mailSession);
message.setContent("This is a test", "text/plain");
message.addRecipient(Message.RecipientType.TO,
new InternetAddress("(e-mail address removed)"));
transport.connect();
transport.sendMessage(message,
message.getRecipients(Message.RecipientType.TO));
transport.close();
} catch (MessagingException ex) {
while ((ex = (MessagingException)ex.getNextException()) != null) {
ex.printStackTrace();
}
}