[JavaMail] class not found SMTPTransport
Bonjour,
j'utilise cette fonction pour envoyer des mails mais elle ne fonctionne pas
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
|
public static void envoi()
{
String smtpHost = "smtp.wanadoo.fr";
String from = "from@wanadoo.fr";
String to = "to@gmail.com";
String username = "from@wanadoo.fr";
String password = "mdp";
Properties props = new Properties();
props.put("mail.smtp.host", smtpHost);
props.put("mail.smtp.auth", "true");
Session session = Session.getDefaultInstance(props);
session.setDebug(true);
MimeMessage message = new MimeMessage(session);
try
{
message.setFrom(new InternetAddress(from));
message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
message.setSubject("Hello");
message.setText("Hello World");
Transport tr = session.getTransport("smtp");
tr.connect(smtpHost, username, password);
message.saveChanges();
//tr.send(message);
/** Genere l'erreur. Avec l authentification, oblige d utiliser sendMessage meme pour une seule adresse... */
tr.sendMessage(message,message.getAllRecipients());
tr.close();
}
catch(Exception e)
{
System.out.println("rate");
}
} |
voici les erreurs :
DEBUG: setDebug: JavaMail version 1.4ea
DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc.,1.4ea]
java.lang.ClassNotFoundException: com.sun.mail.smtp.SMTPTransport
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at javax.mail.Session.getService(Session.java:764)
at javax.mail.Session.getTransport(Session.java:708)
at javax.mail.Session.getTransport(Session.java:651)
at javax.mail.Session.getTransport(Session.java:631)
at PanneauMail.envoi(PanneauMail.java:62)
at Projet.main(Projet.java:196)
rate
Merci de votre aide