My script for sending emails using Office365 with an admin credentials. The script worked about 6 month, ago but recently it has not been working although it has not been changed.
I have tried to remove UseSsl but it did not work.
try { Send-MailMessage -To "[email protected]" -Subject "test" ` -From "[email protected]" ` -SmtpServer 'smtp.office365.com' -Port 587 -UseSsl:$true ` -Credential $Cred -Body "testbody" Write-Host "Message sent to me." -BackgroundColor Black -ForegroundColor Green } catch [System.Exception] { throw $_ }
Here is the exception I get:
Send-MailMessage : Transaction failed. The server response was: 5.2.0 STOREDRV.Submission.Exception:SendAsDeniedException.MapiExceptionSendAsDenied; Failed to process message due to a permanent exception with message Cannot submit message.