• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

javax.mail problem!!!

 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I forgot: the Exception says it can't find the class javax.mail.MessagingException...
 
author
Posts: 3892
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This isn't a web services question. I'm moving this to the Javamail forum.
Kyle
 
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
put the mail.jar in the classpath of the server
 
Bras cause cancer. And tiny ads:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic