Bonjour, j'ai regarder un peu les tutos sur le sujet des mail et donc j'ai essayer d'crire cette petite classe qui suis ... le probleme c'ets qu eje ne sais pas quoi mettre en fait a cette ligne la :


Code : Sélectionner tout - Visualiser dans une fenêtre à part
   props.put("smtp.free.fr", "smtp.free.fr");
je ne comprend pas ce que l'on doit mettre


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
 
package workgroup.mail;
import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
 
 
/**
 *
 * @author Sébastien
 */
public class MailModel {
    protected String from;
    protected String to;
    protected String subject;
    protected String text ;
 
    /** Creates a new instance of MailModel */
 
    public MailModel(String from ,String to, String subject, String text ) {
        this.from = from ;
        this.to = to ;
        this.subject = subject;
        this.text = text;
    }
 
    public void send(){
        try{
        Properties props= System.getProperties();
 
        props.put("smtp.free.fr", "smtp.free.fr");
 
 
        Session s = Session.getInstance(props,null);
 
 
        InternetAddress from = new InternetAddress("truc@hotmail.fr");
        InternetAddress to = new InternetAddress(this.to);
 
        MimeMessage message = new MimeMessage(s);
        message.setFrom(from);
        message.addRecipient(Message.RecipientType.TO, to);
 
        message.setSubject(this.subject);
        message.setText(this.text);
        Transport.send(message);
 
        } catch (AddressException ea) {
            System.out.println(ea);
        }catch(MessagingException me) {
            System.out.println(me);
        }
 
 
    }
 
    public void setFrom(String from){
        this.from = from ;
    }
    public void setTo(String to ){
        this.to = to ;
    }
    public void setSubject(){
        this.subject = subject ;
    }
    public void setText(String text){
        this.text = text ;
    }
 
 
   public static void main (String [] args){
       MailModel mail = new MailModel("truc@hotmail.fr", "moi@free.fr", "essai", "juste un essai");
       mail.send() ;
   }
}