0

I can send from Yahoo and Gmail, but no matter what I do I can't send from hotmail.

public class LiveSenderActivity extends javax.mail.Authenticator {
private String mailhost = "smtp.live.com";
private String user;
private String password;
private Session session;

static {
    Security.addProvider(new com.provider.JSSEProvider());
}

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

    // This connects to the actual mailserver
    Properties props = new Properties();
    props.setProperty("mail.transport.protocol", "smtp");
    props.setProperty("mail.host", mailhost);
    props.put("mail.smtp.port", "587");
    props.put("mail.smtp.starttls.enable", "true");
    props.put("mail.smtp.auth", "true");

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

    session = Session.getDefaultInstance(props, this);
}

I've tried with and without the SSL stuff, and with port 25 instead of 587... Nothing.

Am I doing something wrong? Like I said, yahoo and gmail work like a charm, but not this..

Its not giving me any errors either..

Vic Vuci
  • 6,993
  • 6
  • 55
  • 90
  • Its unfortunate, because our client does. So we need to implement it. And its proving difficult... – Vic Vuci Feb 16 '12 at 18:58
  • A better answer can be found [here](http://stackoverflow.com/questions/9086420/using-javamail-to-send-from-hotmail). – Vic Vuci Jun 21 '13 at 14:30

1 Answers1

1

Does this JavaMail FAQ entry help?

JavaMail 1.4 is capable of sending and reading messages using Hotmail. All that's required is to properly configure JavaMail. I'll illustrate the proper configuration using the demo programs that come with JavaMail - msgshow.java and smtpsend.java.

Let's assume your Hotmail username is "user@hotmail.com" and your password is "passwd".

To read mail from your Hotmail Inbox, invoke msgshow as follows:

java msgshow -D -T pop3s -H pop3.live.com -U user@hotmail.com -P passwd

By reading the msgshow.java source code, you can see how these command line arguments are used in the JavaMail API. You should first try using msgshow as shown above, and once that's working move on to writing and configuring your own program to use Hotmail. The code fragment shown above for connecting to Gmail will also work for connecting to Hotmail by simply changing the host name.

To send a message through Hotmail, invoke smtpsend as follows:

java -Dmail.smtp.starttls.enable=true -Dmail.smtp.port=587 smtpsend
     -d -M smtp.live.com -U user@hotmail.com -P passwd
     -A someotheruser@hotmail.com

(Note that I split the command over three lines for display, but you should type it on one line.)

The smtpsend program uses the System properties when creating the JavaMail Session, so the properties set on the command line will be available to the JavaMail Session.

The smtpsend program will prompt for a subject and message body text. End the message body with ^D on UNIX or ^Z on Windows.

Again, you can read the smtpsend.java source code to see how the command line arguments are used in the JavaMail API. The code fragment shown above for connecting to Gmail will also work for connecting to Hotmail by simply changing the host name and changing the connect call to t.connect(host, 587, username, password). There is, of course, more than one way to use the JavaMail API to accomplish the same goal. This should help you understand the essential configuration parameters necessary to use Hotmail.

Community
  • 1
  • 1
Bill Shannon
  • 29,579
  • 6
  • 38
  • 40
  • I've gone through that before. It didn't explain anything that helped me specifically... – Vic Vuci Feb 16 '12 at 19:16
  • Your code still contains the socket factory stuff you don't need, and you're still using getDefaultInstance instead of getInstance. What does the protocol trace show? Did you read the JavaMail FAQ debugging tips? – Bill Shannon Feb 16 '12 at 23:42