The Send-MgUserMessage cmdlet in Microsoft Graph PowerShell enables administrators and users to send email messages from a Microsoft 365 mailbox programmatically. It works in conjunction with the New-MgUserMessage cmdlet, allowing messages to be created as drafts and then sent.
The Send-MgUserMessage cmdlet is beneficial for:
Before using Send-MgUserMessage, you need to set up Microsoft Graph PowerShell and authenticate with the necessary permissions.
Install the Module
Run the following command to install the Microsoft Graph module:
Install-Module Microsoft.Graph -Scope CurrentUser
This installs the module for the current user without requiring administrative privileges.
Connect to Microsoft Graph
Authenticate and connect to Microsoft Graph with the required permissions:
Connect-MgGraph -Scopes "Mail.Send"
You'll be prompted to sign in using a Microsoft 365 account with the necessary permissions to send emails..
Disconnect After Use
Once you've completed your tasks, always disconnect the session:
Disconnect-MgGraph
This helps maintain security and prevent unnecessary active sessions.
Exploring the Send-MgUserMessage Cmdlet
The Send-MgUserMessage cmdlet is used to send messages that have been created as drafts in a user’s mailbox. It works by specifying the user ID and the message ID of the draft.
Send-MgUserMessage -UserId <String> -MessageId <String>
Sending a Draft Email
# Create the draft message
$draftMessage = @{
subject = "Reminder: Upcoming Meeting"
body = @{
contentType = "HTML"
content = "This is a reminder for your upcoming meeting scheduled for tomorrow at 10 AM."
}
toRecipients = @(@{ emailAddress = @{ address = "jane.doe@domain.com" } })
}
# Create the message and retrieve the MessageId
$message = New-MgUserMessage -UserId "john.doe@domain.com" -BodyParameter $draftMessage
# Send the message
Send-MgUserMessage -UserId "john.doe@domain.com" -MessageId $message.Id
Sending a Follow-Up Email Automatically
# Create the follow-up draft message
$followUpMessage = @{
subject = "Follow-Up: Action Required"
body = @{
contentType = "Text"
content = "Please follow up on the task assigned to you."
}
toRecipients = @(@{ emailAddress = @{ address = "team.member@domain.com" } })
}
# Create and send the follow-up message
$message = New-MgUserMessage -UserId "manager@domain.com" -BodyParameter $followUpMessage
Send-MgUserMessage -UserId "manager@domain.com" -MessageId $message.Id
Sending Bulk Notifications
# Read users from a CSV
$recipients = Import-Csv "recipients.csv"
foreach ($recipient in $recipients) {
# Create draft for each user
$notificationMessage = @{
subject = "Important Update"
body = @{
contentType = "Text"
content = "Please be informed about the recent updates to our policy."
}
toRecipients = @(@{ emailAddress = @{ address = $recipient.Email } })
}
# Create and send the message
$message = New-MgUserMessage -UserId "admin@domain.com" -BodyParameter $notificationMessage
Send-MgUserMessage -UserId "admin@domain.com" -MessageId $message.Id
}
To optimize the use of Send-MgUserMessage, follow these best practices:
1. Can I send emails directly without creating a draft using Send-MgUserMessage?
No, Send-MgUserMessage requires a message draft to be created first.
2. Can I send emails from a shared mailbox using Send-MgUserMessage?
Yes, but you need Send As or Send on Behalf permissions for the shared mailbox.
3. How do I check if an email was sent successfully?
Monitor the sent items folder or enable logging to verify successful delivery.
4. What happens if the recipient’s email is incorrect?
Microsoft 365 will generate a non-delivery report (NDR) if the recipient’s address is invalid.
| Error | Cause | Solution |
| Access Denied | The user does not have Mail.Send permission | Ensure the correct permissions are granted. |
| Invalid Message ID | The message ID provided is incorrect. | Retrieve the correct message ID using New-MgUserMessage |
| Message Not Sent | API rate limit exceeded or misconfigured parameters. | Check API limits and ensure the correct parameters are used. |
| User Not Found | Incorrect User ID provided. | Verify the correct User ID using Get-MgUser before sending messages. |
The Send-MgUserMessage cmdlet is a powerful tool for automating email dispatch within Microsoft 365. By leveraging its capabilities, IT administrators can streamline email communication, send follow-ups, and manage bulk notifications efficiently.
Follow best practices and troubleshooting steps to ensure smooth and secure email sending using Microsoft Graph PowerShell.
Did You Know? Managing Microsoft 365 applications is even easier with automation. Try our Graph PowerShell scripts to automate tasks like generating reports, cleaning up inactive Teams, or assigning licenses efficiently.
Ready to get the most out of Microsoft 365 tools? Explore our free Microsoft 365 administration tools to simplify your administrative tasks and boost productivity.
© Your Site Name. All Rights Reserved. Design by HTML Codex