You are missing the required permissions on Graph side, use this instead (and make sure to provide consent where needed):
Connect-MgGraph -Scopes "Mail.Send","Mail.Send.Shared","Calendars.ReadWrite"
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I am currently testing the use of PowerShell to automate the sending of emails and conference invitations.
I have confirmed that by executing Send-MgUserMail and New-MgUserEvent commands as a user signed in with the Connect-MgGraph command, it is possible to send mail and conference invitations.
However, when a shared mailbox for which the user has SendAs access right is specified as the sender, the sending fails with the error "Access is denied. Check credentials and try again.".
I run the commands as follows.
Connect-MgGraph -Scopes "Mail.Send", "Calendars.ReadWrite"
#Sign in as a user which has SendAs access right to the shared mailbox
$params = @{
Message = @{
Subject = "Test Mail"
Body = @{
ContentType = "Text"
Content = "This is a test mail."
}
ToRecipients = @(
@{
EmailAddress = @{
Address = "(recipient's email address 1)"
}
}
)
CcRecipients = @(
@{
EmailAddress = @{
Address = "(recipient's email address 2)"
}
}
)
}
SaveToSentItems = "true"
}
Send-MgUserMail -UserId "(shared mailbox address)" -BodyParameter $params
Please let me know why the above fails to send the mail.
Also, when I changed sender to an Microsoft 365 group address for which the user has SendAs access right, the error changed to “Group Shard is used in non-Groups URI.”.
Please let me know why sending emails from a Microsoft 365 group also fails.
You are missing the required permissions on Graph side, use this instead (and make sure to provide consent where needed):
Connect-MgGraph -Scopes "Mail.Send","Mail.Send.Shared","Calendars.ReadWrite"