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
|
public void postMail(String recipients[], String subject,
String from, String nom, String prenom, String mail, String mdp, boolean candidat, String type) throws MessagingException {
boolean debug = false;
//Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
//Set the host smtp address
Properties props = new Properties();
props.put("mail.transport.protocol", "smtp");
props.put("mail.smtp.starttls.enable","true");
props.put("mail.smtp.host", SMTP_HOST_NAME);
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.user", SMTP_AUTH_USER);
props.put("mail.smtp.password", SMTP_AUTH_PWD);
Authenticator auth = new PopupAuthenticator(SMTP_AUTH_USER,SMTP_AUTH_PWD);
Session session = Session.getInstance(props,auth);
session.setDebug(debug);
// create a message
Message msg = new MimeMessage(session);
// set the from and to address
InternetAddress addressFrom = new InternetAddress(from);
msg.setFrom(addressFrom);
InternetAddress[] addressTo = new InternetAddress[recipients.length];
for (int i = 0; i < recipients.length; i++) {
addressTo[i] = new InternetAddress(recipients[i]);
}
msg.setRecipients(Message.RecipientType.TO, addressTo);
// Setting the Subject and Content Type
msg.setSubject(subject);
msg.setSentDate(new Date());
//msg.setContent(message, "text/plain");
msg.setContent("test", "text/html");
SMTPTransport transport = (SMTPTransport)session.getTransport("smtp");
transport.connect(SMTP_HOST_NAME,SMTP_AUTH_USER, SMTP_AUTH_PWD);
transport.sendMessage(msg, msg.getAllRecipients());
transport.close();
} |
Partager