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