IntelliJ Java IDE
The moose likes Other JSE/JEE APIs and the fly likes javax.mail problem!!! Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Reply Bookmark "javax.mail problem!!!" Watch "javax.mail problem!!!" New topic
Author

javax.mail problem!!!

Stefan Elfvinge
Ranch Hand

Joined: Oct 29, 2001
Posts: 52
Compiling and running the code below in main-method in the same class works just fine! The mail goes to the intended recipient with all its proper content. BUT, when trying to instaniate it in a servlet running in a webserver(locally), NoClassDefFoundErroe is thrown!!!??? That is, I do away with the main and instead I do: new CaseMail(string, int) in the Servlet.
What to do?
import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
public class CaseMail
{
private String smtpHost;
private String fromAddress;
//private Address[] toAddresses;
private String toAddress;
private MimeMessage message;
private static String mailLink = "http://C:/bla/bla";
//Argumenten anv�nds �nnu inte, = h�rdkodning under testperiod.
public CaseMail(String fA, int id) //throws AddressException, MessagingException
{
try
{
smtpHost = "172.31.126.54";
fromAddress = fA;
toAddress = "donald.duck@ankeborg.com";
// "stefanelfvinge@hotmail.com";
// "mikael.svardh@eniro.com";
Properties properties = System.getProperties();
properties.put("mail.smtp.host", smtpHost);
Session session = Session.getInstance(properties, null);
message = new MimeMessage(session);
message.setFrom(new InternetAddress(fromAddress));
message.setRecipient(Message.RecipientType.TO, new InternetAddress(toAddress));
//det finns �ven setRecipients f�r multipla mottagaraddresser
message.setSubject("Did it work?");
message.setText(mailLink+id);
Transport.send(message);
}
catch(AddressException ae)
{
System.err.println(ae.getMessage());
}
catch(MessagingException me)
{
System.err.println(me.getMessage());
}
}


Steffe
Stefan Elfvinge
Ranch Hand

Joined: Oct 29, 2001
Posts: 52
I forgot: the Exception says it can't find the class javax.mail.MessagingException...
Kyle Brown
author
Ranch Hand

Joined: Aug 10, 2001
Posts: 3878
This isn't a web services question. I'm moving this to the Javamail forum.
Kyle


Kyle Brown, Author of Persistence in the Enterprise and Enterprise Java Programming with IBM Websphere, 2nd Edition
See my homepage at http://www.kyle-brown.com/ for other WebSphere information.
Kiran Kumar
Ranch Hand

Joined: May 18, 2001
Posts: 107
put the mail.jar in the classpath of the server


Thanks<br /> <br />Kiran <br /> <br />SCEA, SCJP 1.4,<br /> <br />"First they ignore u, then they laugh at u, then they fight u, <br />then u will win<br /> <br />Mahatma Gandhi"
 
 
subject: javax.mail problem!!!
 
Threads others viewed
SendFailedException for sending simple email by using JavaMail
A JavaMail exception, can you explain?
Another java mail question
NoClassDefFoundError JavaMail..........
Not able to run JavaMail class
developer file tools