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
|
public class SisMail {
public static void envoyerEmailText(String SMTP_HOST_NAME,String SMTP_AUTH_USER,String SMTP_AUTH_PWD,
String emailMsgTxt,String emailSubjectTxt,String emailFromAddress,
String[] emailList) throws MessagingException {
boolean debug = false;
Properties props = new Properties();
props.setProperty("mail.transport.protocol", "smtp");
props.setProperty("mail.host", "mail.sispay.net");
props.setProperty("mail.user", "aouatif.elkhou@gmail.com");
props.setProperty("mail.password", "aouatif");
//Authenticator auth = new SMTPAuthenticator();
Session session = Session.getDefaultInstance(props, null);
session.setDebug(debug);
// create a message
Message msg = new MimeMessage(session);
// set the from and to address
InternetAddress addressFrom = new InternetAddress(emailFromAddress);
msg.setFrom(addressFrom);
InternetAddress[] addressTo = new InternetAddress[emailList.length];
for (int i = 0; i < emailList.length; i++) {
addressTo[i] = new InternetAddress(emailList[i]);
}
msg.setRecipients(Message.RecipientType.TO, addressTo);
// Setting the Subject and Content Type
msg.setSubject(emailSubjectTxt);
msg.setContent(emailMsgTxt, "text/plain");
Transport.send(msg);
// }
}
/*Methode d'envoi de type message HTML*/
public void envoyerEmailHTML(String SMTP_HOST_NAME,String SMTP_AUTH_USER,String SMTP_AUTH_PWD,
String emailMsgTxt,String emailSubjectTxt,String emailFromAddress,
String[] emailList) throws MessagingException {
boolean debug = false;
Properties props = new Properties();
props.setProperty("mail.smtp.auth", "true");
props.setProperty("mail.transport.protocol", "smtp");
props.setProperty("mail.host", "mail.sispay.net");
props.setProperty("mail.user", "aouatif.elkhou@gmail.com");
props.setProperty("mail.password", "aouatif");
Authenticator auth = new SMTPAuthenticator();
Session session = Session.getDefaultInstance(props, auth);
session.setDebug(debug);
// create a message
Message msg = new MimeMessage(session);
// set the from and to address
InternetAddress addressFrom = new InternetAddress(emailFromAddress);
msg.setFrom(addressFrom);
InternetAddress[] addressTo = new InternetAddress[emailList.length];
for (int i = 0; i < emailList.length; i++) {
addressTo[i] = new InternetAddress(emailList[i]);
}
msg.setRecipients(Message.RecipientType.TO, addressTo);
// Setting the Subject and Content Type
msg.setSubject(emailSubjectTxt);
msg.setContent(emailMsgTxt, "text/html");
Transport.send(msg);
// }
}
/**
* SimpleAuthenticator is used to do simple authentication when the SMTP
* server requires it.
*/
private class SMTPAuthenticator extends javax.mail.Authenticator {
public PasswordAuthentication getPasswordAuthentication() {
String username = "aouatif.elkhou@gmail.com";
String password = "aouatif";
return new PasswordAuthentication(username, password);
}
}
}je vous en pris aidez moi svp |
Partager