Bonsoir,
Au fait je suis entrain de développer une petite application concernant envoie de mail.tout ça marche très bien et je reçois le mail mais le problème lorsque je reçois le mail l'adresse de ce qui envoie est la même de ce qui reçoit le message.
J'aimerai bien avoir votre aide s'il vous plait.
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 package client; import java.util.Properties; import javax.mail.Address; import javax.mail.Message; import javax.mail.MessagingException; import javax.mail.PasswordAuthentication; import javax.mail.Session; import javax.mail.Transport; import javax.mail.internet.InternetAddress; import javax.mail.internet.MimeMessage; public class SendMailTLS { String from; String texte=""; String subject=""; public String getTexte() { return texte; } public void setTexte(String texte) { this.texte = texte; } public String getSubject() { return subject; } public void setSubject(String subject) { this.subject = subject; } public String getFrom() { return from; } public void setFrom(String from) { this.from = from; } final String username = "....."; final String password = "....."; public void sentd(){ Properties props = new Properties(); props.put("mail.smtp.auth", "true"); props.put("mail.smtp.starttls.enable", "true"); props.put("mail.smtp.host", "smtp.gmail.com"); props.put("mail.smtp.port", "587"); Session session = Session.getInstance(props, new javax.mail.Authenticator() { protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(username, password); } }); try { Message message = new MimeMessage(session); message.setFrom(new InternetAddress(from)); message.setRecipients(Message.RecipientType.TO, InternetAddress.parse("adresse_distinataire@gmail..")); message.setSubject(texte); message.setText(subject); Transport.send(message); System.out.println("Done"); } catch (MessagingException e) { throw new RuntimeException(e); } } }
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 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core" xmlns:p="http://primefaces.org/ui"> <h:head> </h:head> <body> <h:form> <h:panelGrid columns="2"> From: <h:panelGroup> <h:inputText size="15" id="name" value="#{sendMailTLS.from}" required="true" requiredMessage="Required"/> <h:message for="name" style="color:red"/> </h:panelGroup> Subject: <h:panelGroup> <h:inputText size="30" id="subject" value="#{sendMailTLS.texte}" required="true" requiredMessage="Required"/> <h:message for="subject" style="color:red"/> </h:panelGroup> Message: <h:panelGroup> <h:inputTextarea cols="45" rows="15" id="message" value="#{sendMailTLS.subject}" required="true" requiredMessage="Required"/> <h:message for="message" style="color:red"/> </h:panelGroup> <h:commandButton value="Send" action="#{sendMailTLS.sentd}"/> </h:panelGrid> </h:form> </body> </html>
Partager