Привет, я в настоящее время разрабатываю приложение Java, которое отправит почту нескольким получателям через Java Mail API (1.6.2), я настраиваю SMTP в соответствии с проблемой Microsoft Docs, что код работает с моим личным идентификатором электронной почты Hotmail, но он не выполняет корпоративный офис 365. Аутентификация безуспешно [pn1pr0101ca0066.indprd01.prod.outlook.com] < /p>
POP и IMAP работают (получение почты), и я могу войти в систему с паролем в Office 365, я тоже попробовал изменить пароль.User user = Credentials.ACC;
Properties props = new Properties();
props.put("mail.smtp.host", "smtp.office365.com");//outlook.office365.com
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.port", "587");//25
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.transport.protocol", "smtp");
//props.put("mail.smtp.ssl.enable", true);
Session session = Session.getInstance(props, new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(user.getUsername(), user.getPassword());
}
});
session.setDebug(true);
try {
MimeMessage msg = new MimeMessage(session);
msg.setFrom(user.getUsername());
msg.setRecipients(Message.RecipientType.TO,
"some@mail.com");
msg.setSubject("Testing SMTP using [" + user.getUsername() + "]");
msg.setSentDate(new Date());
msg.setText("Hey, this is a test from [" + user.getUsername() + "], Sending via Java Mail API");
Transport.send(msg);
System.out.println("Sent Ok");
} catch (MessagingException e) {
System.out.println("Something went wrong");
e.printStackTrace();
}
Подробнее здесь: https://stackoverflow.com/questions/614 ... office-365