Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

javax.mail problem!!!  RSS feed

 
Stefan Elfvinge
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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());
}
}
 
Stefan Elfvinge
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I forgot: the Exception says it can't find the class javax.mail.MessagingException...
 
Kyle Brown
author
Ranch Hand
Posts: 3892
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This isn't a web services question. I'm moving this to the Javamail forum.
Kyle
 
Kiran Kumar
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
put the mail.jar in the classpath of the server
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!