Bonjour,
J'ai developpé un client simple pour l'envoi de mail avec le protocole smtp. Je souhaite joindre un fichier dans le mail. L'envoi du mail se passe bien. J'ai bien un fichier joint dans le mail. Mais ce n'est pas le fichier qui se trouve dans le repertoire courant. D'ailleurs, les champs expéditeurs, objet, etc ... ne sont pas renseigné alors qu'ils le sont dans mon code.

Si quelqu'un a une idée, je suis preneur.

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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
   import java.net.*;
   import java.io.*;  
 
    public class ClientSMTPConsole{
 
      String fin ="FINMESSAGE";
      String CRLF ="\r\n";
      StringBuffer message = new StringBuffer();
      String phrase;
      StringBuffer entete, entete2;
      String nom_serveur, adresse_desti, adresse_expe, objet;
      int port_server = 25;
      Socket socketC = null;
      String messageR =null;
      InputStream is = null;
      PrintWriter fluxSortie = null;
      BufferedReader fluxEntree = null;
      StringBuffer msgAenvoyer;
      PrintWriter PW = null;    
      String message_recu = null;	 
 
       public ClientSMTPConsole(){
         this.saisieArgs();
         this.constrEntete();
         this.saisieCorpsMsg();
         this.lancerEchange(); 
      }
 
       public void saisieArgs(){
         nom_serveur = "10.47.0.8";
			adresse_expe = "test@centralys.com";
			adresse_desti = "test@centralys.com";
			objet = "MISE A JOUR CONNEXION";
      }
 
       public void constrEntete(){
         entete=new StringBuffer("");
   		entete.append("Content-Type: multipart/mixed; boundary=\"didondinaditondelosdudosdodudundodudindon\"\r\n");
			entete.append("--didondinaditondelosdudosdodudundodudindon\r\n");      
			entete.append("From:"+adresse_expe+CRLF);
         entete.append("To:"+adresse_desti+CRLF);
         entete.append("Subject:"+objet+CRLF);
         entete.append("MIME-Version: 1.0"+CRLF);
         entete.append("Content-Type: text/plain; charset=iso-8859-1"+CRLF);
         entete.append("Content-Transfer-Encoding: 8bit"+CRLF);
			entete.append("--didondinaditondelosdudosdodudundodudindon\r\n");
			entete.append("Content-Type: application/octet-stream; name=\"torcy.rdp\"\r\n\r\n");
			entete.append("Content-Transfer-Encoding: base64\r\n");
			entete.append("Content-Disposition: attachment; filename=\"torcy.rdp\"\r\n\r\n");
			entete.append("--didondinaditondelosdudosdodudundodudindon\r\n");
      }
 
       public void saisieCorpsMsg(){
         while(!(phrase="FINMESSAGE").startsWith(fin)){        
				message.append(phrase);
         }
         message.append("\r\n.");
      }
 
		public void lancerEchange(){
         try{
            socketC = new Socket(nom_serveur, port_server);
         }
             catch(UnknownHostException excep1){
               System.out.println("Erreur de création du socket"+excep1);
            }
             catch(IOException excep2){
               System.out.println("Erreur de création du socket"+excep2);
            }
         try{
            fluxSortie = new PrintWriter(new BufferedWriter(new OutputStreamWriter(socketC.getOutputStream())),true);
 
         }
             catch( IOException excep5){
               System.out.println("erreur pr os");
               System.exit(0);
            } 
         try{
            fluxEntree =  new BufferedReader(new InputStreamReader(socketC.getInputStream()));
 
         }
             catch(IOException excep4){
               System.out.println("erreur");
            }
 
         String nom_hote_local=null;
         try{
            nom_hote_local= InetAddress.getLocalHost().getHostName();
         }
             catch(IOException excep4){
               System.out.println("erreur");
            }
         this.lireReponse("220");	
         fluxSortie.println("HELO "+nom_hote_local);
         this.lireReponse("250");
         fluxSortie.println("MAIL FROM: <"+adresse_expe+">");
         this.lireReponse("250");
         fluxSortie.println("RCPT TO: <"+adresse_desti+">");
         this.lireReponse("250");
         fluxSortie.println("DATA");
         this.lireReponse("354");
         fluxSortie.println(entete.toString());
         fluxSortie.println(message.toString());
         this.lireReponse("250");
         fluxSortie.println("QUIT");
         this.lireReponse("221");  
      }
       public void lireReponse(String codeErreur){
         try{
            messageR = fluxEntree.readLine();
         }
             catch( IOException excep6){
               System.out.println("erreur ");
               System.exit(0);
            } 
         if(messageR.startsWith(codeErreur)==true){
            System.out.println(messageR);
         }
         else{
            System.exit(0);
         }
      }
       public static void main(String[]args){
         ClientSMTPConsole client = new ClientSMTPConsole();
      }
   }