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 "myemail@domain.com" -Subject "test" `
        -From "support@domain.com" `
        -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.


Found the solution. The credential used does not have permissions to send email as support@domain.com in -From "support@domain.com"

  • Nice job solving that on your own. – Tim Liston Jan 15 at 20:00
  • How did you actually find the problem? – Michael Hampton Jan 15 at 21:12
  • Well done you solved the issue :) – Kelvin_D Jan 16 at 2:11
  • The following link might be helpful to others with the same issue: docs.microsoft.com/en-us/exchange/mail-flow-best-practices/… – Joe Jan 16 at 2:15
  • @MichaelHampton I just tried the admin email (the credential used to connect to exchange in the above powershell script) for the -From line instead of support@domain.com and that worked. Admin credentials did not have permissions to send email on behalf of (or as) support@domain.com. – Dalian Jan 16 at 10:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.