waqas009 / javamail-android

Automatically exported from code.google.com/p/javamail-android
0 stars 0 forks source link

Can't authenticate with Hotmail #6

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
I cannot authenticate with a hotmail address using JavaMail. I verified that I 
can connect to smtp.live.com via telnet port 587. If I change:

host = "smtp.gmail.com" t.connect(host, username, password); 

It connects to Gmail just fine on the default port and sends an email. 

But if I change the code to:

host = "smtp.live.com" t.connect(host,587, username, password); It gives me the 
following error:

javax.mail.MessagingException: Could not connect to SMTP host: smtp.live.com, 
port: 587;

nested exception is:

java.io.IOException: SSL handshake failure: Failure in SSL library, usually a 
protocol error

error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol 
(external/openssl/ssl/s23_clnt.c:604 0xaf076228:0x00000000)

With session.setDebug(true) I get this info:

09-15 01:57:37.280: INFO/System.out(720): DEBUG: getProvider() returning 
javax.mail.Provider[TRANSPORT,smtps,com.sun.mail.smtp.SMTPSSLTransport,Sun 
Microsystems, Inc.,1.4.1] 09-15 01:57:37.300: INFO/System.out(720): DEBUG SMTP: 
useEhlo true, useAuth true 09-15 01:57:37.310: INFO/System.out(720): DEBUG 
SMTP: trying to connect to host "smtp.live.com", port 587, isSSL true 09-15 
01:57:37.330: INFO/SSLSocketFactory(720): Using factory 
org.apache.harmony.xnet.provider.jsse.OpenSSLSocketFactoryImpl@4007ed70 09-15 
01:57:37.490: DEBUG/NativeCrypto(720): SSL_OP_NO_SSLv3 is set 09-15 
01:57:37.538: ERROR/NativeCrypto(720): Unknown error 1 during connect

Looks like Hotmail isn't playing nice with OpenSSL. Does anyone have a solution 
for this? 

Below is the code to recreate the issue.
Thanks in advance,

J

String host = "smtp.live.com"; 

String username = foo@hotmail;  

String password = "**";  

Transport t = null; 

Properties props = new Properties(); 

props.put("mail.smtps.auth", "true"); 

//props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory"); 

Session session = Session.getInstance(props); 

session.setDebug(true); 

try{ 

MimeMessage msg = new MimeMessage(session); 

msg.setSubject("Testing SMTP-SSL"); 

msg.setContent("This is a test", "text/plain"); 

msg.setFrom(new InternetAddress(username)); 

msg.setRecipients(Message.RecipientType.TO, 

InternetAddress.parse(username, false)); 

t = session.getTransport("smtps"); 

t.connect(host,587, username, password); 

t.sendMessage(msg, msg.getAllRecipients()); 

} catch (Exception e) { 

// TODO Auto-generated catch block 

e.printStackTrace(); 

} finally { 

try { 

t.close(); 

} catch (MessagingException e) { 

// TODO Auto-generated catch block 

e.printStackTrace(); 

} 

} 

Original issue reported on code.google.com by ad...@googoosoftware.com on 3 Oct 2010 at 9:45

GoogleCodeExporter commented 9 years ago
Here are the properties I used to get smtp.live.com to work with 
javamail-android:

props.put("mail.smtp.auth", "true");
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.port", _port);  //This was 25
props.put("mail.smtp.socketFactory.port", _sport);  //This was 587
props.put("mail.smtp.socketFactory.fallback", "false");

I was using a GMail sample to do it and found that this line was interfering 
with the smtp.live.com mail sending, so I commented it out:
//props.put("mail.smtp.socketFactory.class",
//  "javax.net.ssl.SSLSocketFactory");

If I didn't comment it out, this is the error message I'd get

javax.mail.MessagingException: 530 5.7.0 Must issue a STARTTLS command first

Original comment by mend...@gmail.com on 23 Apr 2011 at 1:19