Bonjour;
je viens de faire une fonction mail qui me permet de se connecter a un
serveur smtp avec auhtentification.mon probleme c'est que d'aprés les
traces j'ai eu des choses comme:
keyStore is :
keyStore type is : jks
keyStore provider is :
Timer-0, handling exception: javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?
Timer-0, SEND TLSv1 ALERT: fatal, description = unexpected_message
Timer-0, WRITE: TLSv1 Alert, length = 2
[Raw write]: length = 7
0000: 15 03 01 00 02 02
0A
.......
Timer-0, called closeSocket()
DEBUG SMTP: exception reading response: javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?
ma fonction java:
public void SenderMail(){
System.setProperty("javax.net.debug", "all");
String protocol = "smtp";
String strport = "25";
String serveur= "monserveurmail";
String socketFactory = "javax.net.ssl.SSLSocketFactory";
String smtpAuth = "true";
Properties props = new Properties();
props.put("mail.transport.protocol", protocol);
props.put("mail.smtp.port", strport);
props.put("mail.smtp.starttls.enable","true");
props.put("mail.smtp.auth", smtpAuth);
props.put("mail.smtp.socketFactory.class",
socketFactory);
props.put("mail.smtp.socketFactory.port",
strport);
// 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, serveur,
Integer.parseInt(strport), "", 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("xxx@xxxx.xx"));
mesg.setRecipients(Message.RecipientType.TO,InternetAddress.parse("toto@gmail.com",
false));
mesg.setSubject("test");
mesg.setText("msg for test");
Transport.send(mesg);
}
catch (MessagingException me)
{
me.printStackTrace();
}
}
je pense qu'il faut gerer dns le code le certificats,keystores et truststores.
quelqu'un pourra me fournir des indications?
merci
Afficher la suite