Код: Выделить всё
Microsoft Graph offline_access
Microsoft Graph User.Read
Microsoft Graph Mail.Send
Microsoft Graph openid
Microsoft Graph IMAP.AccessAsUser.All
Microsoft Graph SMTP.Send
Office 365 Exchange Online full_access_as_app
Office 365 Exchange Online POP.AccessAsApp
Office 365 Exchange Online Mail.Send
Office 365 Exchange Online IMAP.AccessAsApp
Код: Выделить всё
PS C:\Users\dx-2102> Get-TransportConfig | Format-List SmtpClientAuthenticationDisabled
SmtpClientAuthenticationDisabled : False
< /code>
Реализованный код для отправки электронной почты (Java): < /p>
Properties prop = new Properties();
prop.put("mail.smtp.auth", "true");
prop.put("mail.smtp.starttls.enable", "true");
prop.put("mail.smtp.host", emailSettings.getSmtp().getHostname());
prop.put("mail.smtp.port", emailSettings.getSmtp().getPort());
prop.put("mail.debug", "true");
prop.put("mail.debug.auth", "true");
prop.put("mail.smtp.auth.xoauth2.disable", "false");
prop.put("mail.smtp.auth.mechanisms", "XOAUTH2");
prop.put("mail.transport.protocol", "smtp");
prop.put("mail.smtp.auth.login.disable", "true");
prop.put("mail.smtp.auth.plain.disable", "true");
session = Session.getInstance(prop);
session.setDebug(true);
String accessToken = getOAuth2AccessToken();
transport = session.getTransport("smtp");
transport.connect(emailSettings.getSmtp().getHostname(), emailSettings.getSmtp().getPort(), emailSettings.getSmtp().getUsername(), tokenForSmtp(emailSettings.getSmtp().getUsername(), accessToken));
/* -- */
transport.sendMessage(mimeMessage, mimeMessage.getAllRecipients());
transport.close();
Код: Выделить всё
String url = "https://login.microsoftonline.com/" + Tenant_ID + "/oauth2/token";
MultiValueMap map = new LinkedMultiValueMap();
map.add("grant_type", "client_credentials");
map.add("response_type", "code");
map.add("client_id", ClientId);
map.add("client_secret", ClientSecret);
map.add("scope","openid offline_access https%3A%2F%2Foutlook.office365.com%2FSMTP.Send ");
RestTemplate restTemplate = new RestTemplate();
ResponseEntity response = restTemplate.postForEntity(url, map, AzureResponse.class);
< /code>
Метод подготовки токена для отправки в процессе SMTP Send-mail < /p>
private String tokenForSmtp(String userName, String accessToken) {
final String ctrlA=Character.toString((char) 1);
final String coded= "user=" + userName + ctrlA+"auth=Bearer " + accessToken + ctrlA+ctrlA;
return Base64.getEncoder().encodeToString(coded.getBytes());
//base64("user=" + userName + "^Aauth=Bearer " + accessToken + "^A^A")
}
< /code>
После отправки электронного письма SMTP я получаю ошибку: < /p>
AUTH XOAUTH2 dXNlcj1zb2ZhQHNvbHV0aW9uZmFjdG9yeWFnLm9ub...=
535 5.7.3 Authentication unsuccessful [VI1PR0202CA0024.eurprd02.prod.outlook.com]
Error on sending email: 535 5.7.3 Authentication unsuccessful [VI1PR0202CA0024.eurprd02.prod.outlook.com]
Подробнее здесь: https://stackoverflow.com/questions/740 ... office-365