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
| public SendMail() {
super();
Properties properties = new Properties();
properties.put("mail.smtp.auth", "true");
properties.put("mail.smtp.host", "ssl0.ovh.net");
properties.put("mail.smtp.port", "465");
//properties.put("mail.smtp.starttls.enable", "true");
properties.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
//properties.put("mail.debug", "true");
//sess = Session.getDefaultInstance(properties, null);
sess = Session.getInstance(properties, new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(Datas.NOREPLY, Datas.PWDNOREPLY);
}
});
}
public void sendMessage() throws MessagingException, UnsupportedEncodingException {
Transport transport=sess.getTransport();
Message message = new MimeMessage(sess);
message.setFrom(new InternetAddress("noreply@xxxxx.xxx", "Site web"));
message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(destinat));
message.setSubject(subject);
message.setContent(content, "text/html; charset=UTF-8");
message.setHeader("Content-Type", "text/html; charset=\"UTF-8\"");
transport.connect();
transport.sendMessage(message, message.getRecipients(Message.RecipientType.TO));
transport.close();
} |
Partager