用户在第三方应用中使用Microsoft 365 Exchangeonline发送通知邮件,设置完用户名和密码,测试发邮件时遇到了问题,报错如下:
535, '5.7.3 Authentication unsuccessful [TYCPR01CA0145.jpnprd01.prod.outlook.com 2024-01-11T09:22:51.090Z 08DC11E16333A637]'
使用Powershell脚本测试smtp
$From = "connect-admin@abc.com"
$To = "419478190@qq.com"
$Subject = "Test PowerShell email from Microsoft 365"
$Body = "PowerShell email from Microsoft O365 "
$Password = "password" | ConvertTo-SecureString -AsPlainText -Force
$Credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $From, $Password
Send-MailMessage -From $From -To $To -Subject $Subject -Body $Body -SmtpServer "smtp.office365.com" -port 587 -UseSsl -Credential $Credential
也收到报错,提示信息如下:
Send-MailMessage : SMTP 服务器要求安全连接或客户端未通过身份验证。 服务器响应为:5.7.57 Client not authenticated to send mail. Error: 535 5.7.139 Authentication unsuccessful, user is locked by your organization's security defaults policy. Contact your administrator. [SI1PR02CA0032.apcprd02.prod.outlook.com 2024-01-12T05:04:29.182Z 08DC12DD25DEAF20]
所在位置 行:7 字符: 1
+ Send-MailMessage -From $From -To $To -Subject $Subject -Body $Body -S ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.Mail.SmtpClient:SmtpClient) [Send-MailMessage],SmtpException
+ FullyQualifiedErrorId : SmtpException,Microsoft.PowerShell.Commands.SendMailMessage
看提示应该是默认安全策略阻止了用户登录。
解决方案:登录Micrsoft EntraID 管理中心,在属性中找到“管理安全默认值”
将安全默认值改为禁用
在重新运行脚本后问题解决,