1

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.

0

1 Answer 1

4

Found the solution. The credential used does not have permissions to send email as [email protected] in -From "[email protected]"

5
  • Nice job solving that on your own. Commented Jan 15, 2019 at 20:00
  • How did you actually find the problem? Commented Jan 15, 2019 at 21:12
  • Well done you solved the issue :) Commented Jan 16, 2019 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/… Commented Jan 16, 2019 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 [email protected] and that worked. Admin credentials did not have permissions to send email on behalf of (or as) [email protected]. Commented Jan 16, 2019 at 10:34

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.