无法通过powershell脚本发送邮件

inkz8wg9  于 2023-02-23  发布在  Shell
关注(0)|答案(1)|浏览(143)

下面是代码:

$TLS12Protocol = [System.Net.SecurityProtocolType] 'Tls12'
[System.Net.ServicePointManager]::SecurityProtocol = $TLS12Protocol
$smtpencryption = 'tls'
$From = "JIT.Batch@duckcreek.com"
$To = "abhishek.chawla@duckcreek.com”
$recipients = "<abhishek.chawla@duckcreek.com>"
[string[]]$To = $recipients.Split(',')
$Cc = "abhishek.chawla@duckcreek.com"
$Subject = "JITAppointment batch Started on StateAuto Production"
$Body = "JITAppointment batch Started on SA Production for latest file"
$SMTPServer = "smtp.office365.com"
$SMTPPort = "587"
$secpasswd = ConvertTo-SecureString "*******" -AsPlainText -Force
$mycreds = New-Object System.Management.Automation.PSCredential($from, $secpasswd)
Send-MailMessage -From $From -to $To -Cc $Cc -Subject $Subject -Body $Body -BodyAsHtml -SmtpServer $SMTPServer -Port $SMTPPort -UseSsl -Credential $mycreds
#Send-MailMessage -From $From -to $To -Cc $Cc -Subject $Subject -Body $Body -SmtpServer $SMTPServer

当我在服务器上运行这个时,我得到下面的错误:
enter image description here
我无法通过这个代码发送邮件。

wgmfuz8q

wgmfuz8q1#

我可以看到你正在通过smtp.office365.com发送。Microsoft 365不再支持基本身份验证,这意味着你无法使用Send-MailMessage。替代方法包括Send-MgUserMail,它是模块Microsoft.Graph.Users.Actions的一部分

相关问题