未知的SMTP主机:smtp.outlook.com

时间:2012-12-17 08:52:39

标签: outlook smtp javamail

我提出了一个需要发送电子邮件的申请。它以前工作过,但是当我今天要运行它时,它抛出java.net.UnknownHostException: smtp.outlook.com。它过去常常工作,在outlook配置上做了一些改变吗?

这是我的代码:

    Properties props = new Properties();
    props.put("mail.smtp.auth", "true");
    props.put("mail.smpt.host", "smtp.outlook.com");
    props.put("mail.smtp.port", "587");
    props.put("mail.smtp.starttls.enable", "true");

    Session session = Session.getInstance(props, null);
    try {
        transport = session.getTransport("smtp");
        try {
            transport.connect("smtp.outlook.com", username, wachtwoord);
        } catch (MessagingException ex) {
            ex.printStackTrace();
        }
    } catch (NoSuchProviderException ex) {
        ex.printStackTrace();
    }

它会抛出以下错误:

javax.mail.MessagingException: Unknown SMTP host: smtp.outlook.com;
  nested exception is:
    java.net.UnknownHostException: smtp.outlook.com
    at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1932)
    at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:638)
    at javax.mail.Service.connect(Service.java:295)
    at javax.mail.Service.connect(Service.java:176)
    at retourberichten.VerstuurEmail.SendEmail.VerstuurTest(SendEmail.java:143)
    at retourberichten.StartApplicatie.App.main(App.java:46)
Caused by: java.net.UnknownHostException: smtp.outlook.com
    at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:178)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:391)
    at java.net.Socket.connect(Socket.java:579)
    at java.net.Socket.connect(Socket.java:528)
    at com.sun.mail.util.SocketFetcher.createSocket(SocketFetcher.java:288)
    at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:231)
    at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1900)
    ... 5 more
java.lang.IllegalStateException: Not connected

非常感谢任何帮助,

谢谢!

1 个答案:

答案 0 :(得分:2)

SMTP服务器应该是smtp.live.com而不是smtp.outlook.com

http://www.groovypost.com/howto/outlook.com-settings-pop3-smtp-imap/