How to send email from a shared mailbox or Microsoft 365 group with the Send-MgUserMail command?

S.Imai 20 Reputation points
2025-06-19T09:35:48.3933333+00:00

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.

Microsoft Security | Microsoft Graph
0 comments No comments
{count} votes

Accepted answer
  1. Vasil Michev 119.5K Reputation points MVP Volunteer Moderator
    2025-06-19T12:23:22.1033333+00:00

    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"
    
    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.