mon bout de code:
public void SenderMail(){
System.setProperty("javax.net.debug", "all");
String protocol = "SMTPS";
String socketFactory = "javax.net.ssl.SSLSocketFactory";
String smtpAuth = "true";
Properties props = new Properties();
props.put("mail.transport.protocol", protocol);
props.put("mail.SMTPS.port", "25");
props.put("mail.SMTPS.starttls.enable","true");
props.put("mail.SMTPS.auth", smtpAuth);
props.put("mail.SMTPS.socketFactory.class", socketFactory);
props.put("mail.SMTPS.socketFactory.port", "25");
// Creating mail session
session = Session.getDefaultInstance(props, new Authenticator() {
protected javax.mail.PasswordAuthentication getPasswordAuthentication() {
return new javax.mail.PasswordAuthentication(username, password);
}
});
URLName url = new URLName(protocol, "serveurmail","25", "", username, password);
com.sun.mail.smtp.SMTPSSLTransport transport = new com.sun.mail.smtp.SMTPSSLTransport(session, url);
transport.setStartTLS(true);
}
}
session.setDebug(true);
try {
Message mesg = new MimeMessage(session);
mesg.setFrom(new InternetAddress("sendername");
mesg.setRecipients(Message.RecipientType.TO,InternetAddress.parse("toto@gmail.com", false));
mesg.setSubject("mailObjet");
mesg.setText("mailText");
Transport.send(mesg);
}
catch (MessagingException me)
{
me.printStackTrace();
}
}
mon bout de code: