1

我做了一个需要发送电子邮件的应用程序。它以前工作过,但是当我今天想运行它时,它抛出了一个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

非常感谢任何帮助,

谢谢!

4

1 回答 1

2

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

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

于 2013-05-21T12:41:41.440 回答