我在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,因为我已经检查了它。如果会话被创建,那么我面临这种异常的原因是什么?