Bonjour je suis débutan en java j'essaye d'envoyé un mail avec java et mon serveur que j'utilise utilise une connexion sécurisé avec authentification pour l'envoie de mail
comment faire ?
voila mon code qui peut m'aidez ????

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
import javax.mail.internet.*;
import javax.mail.*;
import java.util.*;
 
/**
 * Classe permettant d'envoyer un mail.
 */
public class TestMail {
   private final static String MAILER_VERSION = "Java";
   public static boolean envoyerMailSMTP(String serveur, boolean debug) {
         boolean result = false;
         try {
                  Properties prop = System.getProperties();
                  prop.put("mail.smtp.host", serveur);
                  Session session = Session.getDefaultInstance(prop,null);
                  Message message = new MimeMessage(session);
                  message.setFrom(new InternetAddress("nabil.chouaieb@gnet.tn"));
                  InternetAddress[] internetAddresses = new InternetAddress[1];
                  internetAddresses[0] = new InternetAddress("chouaieb.n@hotmail.com");
                  message.setRecipients(Message.RecipientType.TO,internetAddresses);
                  message.setSubject("Test");
                  message.setText("test mail");
                  message.setHeader("X-Mailer", MAILER_VERSION);
                  message.setSentDate(new Date());
                  session.setDebug(debug);
                  Transport.send(message);
                  result = true;
         } catch (AddressException e) {
                  e.printStackTrace();
         } catch (MessagingException e) {
                  e.printStackTrace();
         }
         return result;
   }
 
   public static void main(String[] args) {
         TestMail.envoyerMailSMTP("smtp.gnet.tn",true);
   }
}


et le code erreur :


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
50
51
52
53
54
55
56
57
58
59
60
61
DEBUG: setDebug: JavaMail version 1.4.1
DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc]
DEBUG SMTP: useEhlo true, useAuth false
DEBUG SMTP: trying to connect to host "smtp.gnet.tn", port 25, isSSL false
220 *****************************************
DEBUG SMTP: connected to host "smtp.gnet.tn", port: 25
 
EHLO PC-de-Chouaieb
250-smtp.gnet.tn
250-PIPELINING
250-SIZE 10240000
250-VRFY
250-ETRN
250-AUTH LOGIN
250 8BITMIME
DEBUG SMTP: Found extension "PIPELINING", arg ""
DEBUG SMTP: Found extension "SIZE", arg "10240000"
DEBUG SMTP: Found extension "VRFY", arg ""
DEBUG SMTP: Found extension "ETRN", arg ""
DEBUG SMTP: Found extension "AUTH", arg "LOGIN"
DEBUG SMTP: Found extension "8BITMIME", arg ""
DEBUG SMTP: use8bit false
MAIL FROM:<nabil.chouaieb@gnet.tn>
250 Ok
RCPT TO:<nabil.chouaieb@gnet.tn>
553 <nabil.chouaieb@gnet.tn>: Sender address rejected: not logged in
DEBUG SMTP: Invalid Addresses
DEBUG SMTP:   nabil.chouaieb@gnet.tn
DEBUG SMTP: Sending failed because of invalid destination addresses
RSET
250 Ok
javax.mail.SendFailedException: Invalid Addresses;
  nested exception is:
	com.sun.mail.smtp.SMTPAddressFailedException: 553 <nabil.chouaieb@gnet.tn>: Sender address rejected: not logged in
 
	at com.sun.mail.smtp.SMTPTransport.rcptTo(SMTPTransport.java:1294)
	at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:635)
	at javax.mail.Transport.send0(Transport.java:189)
	at javax.mail.Transport.send(Transport.java:118)
	at TestMail.envoyerMailSMTP(TestMail.java:26)
	at TestMail.main(TestMail.java:37)
Caused by: com.sun.mail.smtp.SMTPAddressFailedException: 553 <nabil.chouaieb@gnet.tn>: Sender address rejected: not logged in
 
	at com.sun.mail.smtp.SMTPTransport.rcptTo(SMTPTransport.java:1145)
	... 5 more
QUIT
221 Bye
javax.mail.SendFailedException: Invalid Addresses;
  nested exception is:
	com.sun.mail.smtp.SMTPAddressFailedException: 553 <nabil.chouaieb@gnet.tn>: Sender address rejected: not logged in
 
	at com.sun.mail.smtp.SMTPTransport.rcptTo(SMTPTransport.java:1294)
	at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:635)
	at javax.mail.Transport.send0(Transport.java:189)
	at javax.mail.Transport.send(Transport.java:118)
	at TestMail.envoyerMailSMTP(TestMail.java:26)
	at TestMail.main(TestMail.java:37)
Caused by: com.sun.mail.smtp.SMTPAddressFailedException: 553 <nabil.chouaieb@gnet.tn>: Sender address rejected: not logged in
 
	at com.sun.mail.smtp.SMTPTransport.rcptTo(SMTPTransport.java:1145)
	... 5 more

et mercii