Bonjour à tous,
j'essaye d'introduire dans une application sur laquelle je travaille la possibilité d'envoyer un mail. Pour l'instant j'essaye un programme test que j'ai trouvé sur le web et que j'ai adapté.
Voici le bout de code qui nous intéresse:
--------------
public static void send(String smtpServer, String to, String from
, String subject, String body) {
try {
Properties props = System.getProperties();
// -- Attaching to default Session, or we could start a new one --
props.put("mail.smtp.host", smtpServer);
Session session = Session.getDefaultInstance(props, null);
// -- Create a new message --
Message msg = new MimeMessage(session);
msg.setText(body);
// -- Set the FROM and TO fields --
msg.setFrom(new InternetAddress(from));
msg.setRecipients(Message.RecipientType.TO,
InternetAddress.parse(to, false));
try{
//msg.setText(body);
}catch(NoClassDefFoundError ex){
ex.printStackTrace();
}
// -- Set some other header information --
msg.setHeader("X-Mailer", "LOTONtechEmail");
msg.setSentDate(new Date());
// -- Send the message --
Transport.send(msg);
System.out.println("Message sent OK.");
}
catch (Exception ex) {
System.out.println("ERREUR!");
ex.printStackTrace();
}
}
-------------
j'ai systématiquement l'exception:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/geronimo/mail/util/ASCIIUtil
à la ligne "msg.setText(body)". Je ne comprends pas pourquoi cette exception survient à cette endroit et pas avant, à "msg.setForm(...)" par exemple.
En mettant l'instruction en commentaire, j'ai une autre exception:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/geronimo/mail/util/SessionUtil
à la ligne Transport.send(msg).
j'ai ajouté les jar's qu'ils faut, et mon serveur smtp marche (j'ai essayé avec telnet).
Voici une liste des jars que j'ai:
activation.jar
dnsjava-2.0.3.jar
dsn.jar
imap.jar
pop3.jar
smtp.jar
mail.jar
mailapi.jar
sendmail.jar
Ceci dit je ne vois comment ça pourrait être un problème de jar's, vu que l'exception est jetée pour une méthose et pas pour une autre!
J'utilise Intellij IDEA si jamais...
Quelqu'un aurait une idée!? Merci!
Partager