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
|
public class SendMail {
private String expediteur;
private String destinataire;
private String serveur;
private int port =25;
private String message;
public SendMail(... ){
//On fait les affectations
..........
send();
}
private void send(){
new Thread(){
public void run(){
PrintWriter question;
BufferedReader reponse;
String s;
Socket socket;
try {
socket = new Socket(InetAddress.getByName(serveur),port);
question = new PrintWriter(new BufferedWriter (new OutputStreamWriter (socket.getOutputStream())),true);
reponse = new BufferedReader(new InputStreamReader (socket.getInputStream()));
s = reponse.readLine();
question.println("HELO coucou");
s = reponse.readLine();
question.println("MAIL FROM: <"+expediteur+">");
s = reponse.readLine();
question.println("RCPT TO: <"+destinataire+">");
s = reponse.readLine();
question.println("DATA");
s = reponse.readLine();
question.println(message + "\r\n.\r\n");
s = reponse.readLine();
question.println("QUIT\r\n");
s = reponse.readLine();
question.close();
reponse.close();
socket.close();
javax.swing.JOptionPane.showMessageDialog(null, "Mail envoyé avec succes\n" , "Informations ...", javax.swing.JOptionPane.INFORMATION_MESSAGE);
} catch ( Exception e ) {javax.swing.JOptionPane.showMessageDialog(null, "Impossible d'envoyer le message\n Verifier les parametres" + "\n" + e.getClass().getName() , "Erreur Fatale ...", javax.swing.JOptionPane.ERROR_MESSAGE);}
}}.start();
} |
Partager