未知的SMTP主机:outlook.office365.com;

时间:2016-08-11 04:22:55

标签: java email outlook

我在java中编写代码来发送邮件。我面临的问题是UnknownHostException。我使用SMTP主机作为outlook.office.com作为电子邮件帐户,我想发送邮件是公司的,并使用outlook访问。这是代码。

Properties props=new Properties();
        props.put("mail.smtp.auth","true");
        props.put("mail.smtp.starttls.enable","true");
        props.put("mail.smtp.host","outlook.office365.com");
        props.put("mail.smtp.port","587");
        Session session=Session.getInstance(props, new Authenticator(){
            protected PasswordAuthentication getPasswordAuthentication(){
                return new PasswordAuthentication(sender, password);
            }
        });

会话对象不为null,因为我已经检查了它。如果会话被创建,那么我面临这种异常的原因是什么?

1 个答案:

答案 0 :(得分:-1)

更改

props.put("mail.smtp.host","outlook.office365.com");

props.put("mail.smtp.host","smtp.office365.com");

props.put("mail.smtp.host", "m.outlook.com");

有关详细信息,请访问thisthis网站。