8

I've got gmail and yahoo working, but not hotmail. Here's what I have, what am I doing wrong?

private String mailhost = "smtp.live.com";

    public hotmailSenderActivity(String user, String password) {   
    this.user = user;   
    this.password = password;   

  //This connects to the actual mailserver
    Security.addProvider(new com.provider.JSSEProvider());
    Properties props = new Properties();   
    props.setProperty("mail.transport.protocol", "smtp");   
    props.setProperty("mail.host", mailhost); 
    props.put("mail.smtp.starttls.enable", "true");  
    props.put("mail.smtp.auth", "true");   
    props.put("mail.smtp.port", "587");   
    props.put("mail.smtp.socketFactory.port", "587");   
    props.put("mail.smtp.socketFactory.class",   
            "javax.net.ssl.SSLSocketFactory");   
    props.put("smtp.starttls.enable", "true");
    props.put("mail.smtp.socketFactory.fallback", "false");   
    props.setProperty("mail.smtp.quitwait", "false");   

    session = Session.getDefaultInstance(props, this);  

I have tried port 25 + 587 without the SSL stuff. I have tried port 465 WITH the SSL stuff. The email and password are correct (Ive hard coded them to be sure).

I don't receive any errors... So whats the problem?

Vic Vuci
  • 6,993
  • 6
  • 55
  • 90
  • did you find this code from [this](http://stackoverflow.com/questions/2020088/sending-email-in-android-using-javamail-api-without-using-the-default-android-a/2033124#2033124) – Deepak Feb 16 '12 at 20:20
  • Yes, and like I said, it worked wonderfully for gmail and yahoo. – Vic Vuci Feb 16 '12 at 20:22

2 Answers2

20

1) use debug output:

session.setDebug(true);

2) hotmail smtp server starts non-ssl connection on port 25 or 587, and uses starttls after initial connection; thus remove lines

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

3) mimimum amount of settings is then:

    props.setProperty("mail.transport.protocol", "smtp");
    props.setProperty("mail.host", "smtp.live.com");
    props.put("mail.smtp.starttls.enable", "true");
    props.put("mail.smtp.auth", "true");

this assumes port is 25, otherwise add props.put("mail.smtp.port", "587");

4) yet even nicer looks this:

    ...
    props.put("mail.smtp.starttls.enable", "true");
    Session session = Session.getDefaultInstance(props);
    Transport trans = session.getTransport("smtp");
    trans.connect("smtp.live.com", 25, "user", "pass");

now you're connected, use methods of Transport

Pointer Null
  • 39,597
  • 13
  • 90
  • 111
2

http://www.oracle.com/technetwork/java/javamail/faq/index.html#hotmail

Get rid of all that socket factory stuff, you don't need it.

Bill Shannon
  • 29,579
  • 6
  • 38
  • 40
  • Anything else I need to get rid of? Didn't change anything when I removed those. – Vic Vuci Jan 31 '12 at 20:56
  • Did you read the FAQ? It'll tell you what to do when things don't work. – Bill Shannon Feb 01 '12 at 02:19
  • Ok, and again, the FAQ tells you what to do what things don't work. One of the things it tells you to do is to run with session debugging turned on and post the protocol trace. Did you try that? That might actually provide the information we need to help you. – Bill Shannon Feb 02 '12 at 21:49