Bonjour,
J'essaie depuis ce matin de faire un envoi de mail simple via une méthode java, sans succès pour le moment. J'aimerai donc avoir des avis sur ce qui n'irait pas.
Le code de ma fonction java est le suivant (certainement le même que beaucoup) :
Service SMTP : Etant sur un réseau d'entreprise et donc ne pouvant dialoguer directement avec des serveurs smtp externe, j'ai installer les utilitaires window pour avoir
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
40
41
42
43
44
45
46
47
48
49 try{ String protocol = "smtp"; String server = "127.0.0.1"; String message = "corps du message"; String title = "Email test"; String from = "name@bidule.com"; String to = "name@bidule.com"; Properties myProperties = new Properties(); myProperties.put("mail." + protocol + ".host",server); Session mySession = Session.getDefaultInstance(myProperties,null); mySession.setDebug(true); Message myMessage = new MimeMessage(mySession); myMessage.setFrom(new InternetAddress(from)); InternetAddress[] myAddress = new InternetAddress[1]; myAddress[0] = new InternetAddress(to); myMessage.setRecipients(Message.RecipientType.TO, myAddress); myMessage.setSubject(title); myMessage.setText(message); myMessage.setSentDate(new Date()); myMessage.saveChanges(); //Transport.send(myMessage); Transport transport = mySession.getTransport("smtp"); transport.connect(); transport.sendMessage(myMessage,myMessage.getRecipients(Message.RecipientType.TO)); /* SMTPTransport transport = (SMTPTransport)mySession.getTransport(server); transport.connect(); transport.sendMessage(myMessage, myMessage.getAllRecipients()); transport.close(); */ done = true; }catch( AddressException e ){ System.err.println("Address exception : "+e.getMessage()); e.printStackTrace(); }catch( MessagingException e ){ System.err.println("Messaging exception : "+e.getMessage()); e.printStackTrace(); }
un SMTP local à ma machine.
Classpath : Pour ce qui est du classpath, j'ai inclus 'activation.jar', 'mail.jar', 'smtp.jar' et mailapi.jar', les deux derniers venant de la version javamail 1.4.2.
Erreur : Lors de l'exécution, j'obtiens le message suivant :
Ce message d'erreur pointant sur la ligne d'envoi du message (transport.send(..))
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc] java.lang.reflect.InvocationTargetException at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27) at java.lang.reflect.Constructor.newInstance(Constructor.java:274) at javax.mail.Session.getService(Session.java:607) at javax.mail.Session.getTransport(Session.java:541) at javax.mail.Session.getTransport(Session.java:484) at javax.mail.Session.getTransport(Session.java:464) at org.epo.bli.scenario.util.Email.sendEmailSMTP(Email.java:56) at org.epo.bli.scenario.util.Email.main(Email.java:143) Caused by: java.lang.NoSuchMethodError: javax.mail.Session.getDebugOut()Ljava/io/PrintStream; at com.sun.mail.smtp.SMTPTransport.<init>(Unknown Source) at com.sun.mail.smtp.SMTPTransport.<init>(Unknown Source) ... 10 more Messaging exception : smtp javax.mail.NoSuchProviderException: smtp at javax.mail.Session.getService(Session.java:611) at javax.mail.Session.getTransport(Session.java:541) at javax.mail.Session.getTransport(Session.java:484) at javax.mail.Session.getTransport(Session.java:464) at org.epo.bli.scenario.util.Email.sendEmailSMTP(Email.java:56) at org.epo.bli.scenario.util.Email.main(Email.java:143)
J'ai eu beau tenter de mettre à jour mes librairies jar, virer certaines (toutes les configurations ont été faite), rien n'y fait, j'ai toujours la même erreur.
Est-ce que quelqun pourrait m'aider sur ce sujet s'il vous plait ?
Cordialement.
Partager