Bonjour,

J'ai besoin d'envoie des mail via une application Java grace au serveur EXHANGE de Microsoft et l'API JavaMail Pour cella j'ai rédiger deux classe. Le serveur EXCHANGE me refuse toujours l'envoie de mail vers toutes les adresses. Pourtant en passant par Outlook aucun problème.

Voici mon code

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
62
63
64
65
66
67
package classes;
 
import java.util.Properties;
 
import javax.mail.Authenticator;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
 
public class SendMail {
 
 
	public static void sendMail(String message_dest,String message_objet,String message_corps){
 
 
		/** Objet session de JavaMail. */
		Session session;
		/** Objet message de JavaMail. */
		Message mesg;
 
		//		 Nous devons passer les informations au serveur de messagerie sous
		//		 forme de propriétés car JavaMail en comporte beaucoup...
		Properties props = new Properties();
 
		//		 Votre réseau doit donner au serveur SMTP local le nom "nom_du_serveur_smtp"
 
		props.put("mail.smtp.host", "Nom du serveur SMTP");
 
		//		 Créer l’objet Session.
		Authenticator auth = new MyAuthentificator();//USERSMTP et PASSWDSMTP
		session = Session.getDefaultInstance(props, auth);
		session.setDebug(true); //activer le mode verbeux !
 
		try {
			//		 Créer un message.
			mesg = new MimeMessage(session);
 
			//		 Adresse From - Indiquer la provenance du message
			mesg.setFrom(new InternetAddress("toto@domain.com"));
 
			//		 Adresse TO.
			InternetAddress toAddress = new InternetAddress(message_dest);
			mesg.addRecipient(Message.RecipientType.TO, toAddress);
 
			//		 Objet.
			mesg.setSubject(message_objet);
 
			//		 Corps du message.
			mesg.setText(message_corps);
 
			//		 Enfin, envoyer le message !
			Transport.send(mesg);
 
		} catch (MessagingException ex) {
			while ((ex = (MessagingException)ex.getNextException()) != null) {
				ex.printStackTrace();
			}
		}
	}
 
	public static void main(String[] args){
		sendMail("toto@aol.com", "bonjour","bonjour");
	}
}
classe MyAuthentificator
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
public class MyAuthentificator extends Authenticator {
 
	public PasswordAuthentication getAuthentification(){
		String login = "login";
		String mdp = "pass";
 
		return new PasswordAuthentication(login, mdp);
	}
}
Voici ce que me donne l'excecution
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
DEBUG: setDebug: JavaMail version 1.4ea
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 "serveur smtp exchange", port 25, isSSL false
220 serveur smtp exchange Microsoft ESMTP MAIL Service, Version: 6.0.3790.211 ready at  Mon, 2 Jul 2007 15:29:27 +0200 
DEBUG SMTP: connected to host "serveur smtp exchange", port: 25
 
EHLO J67053
250-serveur smtp exchange Hello [XXX.XXX.XXX.XXX]
250-TURN
250-SIZE
250-ETRN
250-PIPELINING
250-DSN
250-ENHANCEDSTATUSCODES
250-8bitmime
250-BINARYMIME
250-CHUNKING
250-VRFY
250-X-EXPS GSSAPI NTLM LOGIN
250-X-EXPS=LOGIN
250-AUTH GSSAPI NTLM LOGIN
250-AUTH=LOGIN
250-X-LINK2STATE
250-XEXCH50
250 OK
DEBUG SMTP: Found extension "TURN", arg ""
DEBUG SMTP: Found extension "SIZE", arg ""
DEBUG SMTP: Found extension "ETRN", arg ""
DEBUG SMTP: Found extension "PIPELINING", arg ""
DEBUG SMTP: Found extension "DSN", arg ""
DEBUG SMTP: Found extension "ENHANCEDSTATUSCODES", arg ""
DEBUG SMTP: Found extension "8bitmime", arg ""
DEBUG SMTP: Found extension "BINARYMIME", arg ""
DEBUG SMTP: Found extension "CHUNKING", arg ""
DEBUG SMTP: Found extension "VRFY", arg ""
DEBUG SMTP: Found extension "X-EXPS", arg "GSSAPI NTLM LOGIN"
DEBUG SMTP: Found extension "X-EXPS=LOGIN", arg ""
DEBUG SMTP: Found extension "AUTH", arg "GSSAPI NTLM LOGIN"
DEBUG SMTP: Found extension "AUTH=LOGIN", arg ""
DEBUG SMTP: Found extension "X-LINK2STATE", arg ""
DEBUG SMTP: Found extension "XEXCH50", arg ""
DEBUG SMTP: Found extension "OK", arg ""
DEBUG SMTP: use8bit false
MAIL FROM:<toto@domain.com>
250 2.1.0 toto@domain.com....Sender OK
RCPT TO:<toto@domain.com>
550 5.7.1 Unable to relay for toto@domain.com
DEBUG SMTP: Invalid Addresses
DEBUG SMTP:   toto@domain.com
DEBUG SMTP: Sending failed because of invalid destination addresses
RSET
250 2.0.0 Resetting
javax.mail.SendFailedException: Invalid Addresses;
  nested exception is:
	com.sun.mail.smtp.SMTPAddressFailedException: 550 5.7.1 Unable to relay for toto@domain.com
 
	at com.sun.mail.smtp.SMTPTransport.rcptTo(SMTPTransport.java:1196)
	at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:584)
	at javax.mail.Transport.send0(Transport.java:169)
	at javax.mail.Transport.send(Transport.java:98)
	at classes.SendMail.sendMail(SendMail.java:55)
	at classes.SendMail.main(SendMail.java:65)
Caused by: com.sun.mail.smtp.SMTPAddressFailedException: 550 5.7.1 Unable to relay for toto@domain.com
 
	at com.sun.mail.smtp.SMTPTransport.rcptTo(SMTPTransport.java:1047)
	... 5 more
QUIT
221 2.0.0 dfrjeummx01.ddom.ad.corp Service closing transmission channel
com.sun.mail.smtp.SMTPAddressFailedException: 550 5.7.1 Unable to relay for toto@domain.com
 
	at com.sun.mail.smtp.SMTPTransport.rcptTo(SMTPTransport.java:1047)
	at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:584)
	at javax.mail.Transport.send0(Transport.java:169)
	at javax.mail.Transport.send(Transport.java:98)
	at classes.SendMail.sendMail(SendMail.java:55)
	at classes.SendMail.main(SendMail.java:65)
Pour information toto@domain.com est une adresse mail qui fonctionne sur le serveur avec Outlook

Merci pour toute aide