Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
278 views
Welcome To Ask or Share your Answers For Others

1 Answer

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...