How to Use Send-MgUserMessage to Send M365 Mails?

Sending emails programmatically in Microsoft 365 (M365) has become more accessible and efficient thanks to Graph PowerShell. One powerful cmdlet that helps with this task is Send-MgUserMessage. In this guide, we'll walk you through everything you need to know to start sending mails effortlessly.


What is Send-MgUserMessage?

Send-MgUserMessage is a Microsoft Graph PowerShell cmdlet that allows you to send an existing draft email from a user's mailbox in Microsoft 365. Instead of crafting and sending an email in one step, you first create a draft (using New-MgUserMessage) and then send it using Send-MgUserMessage.

This two-step process provides flexibility for scenarios where you might want to review or modify a message before dispatching it.


Why Use Send-MgUserMessage?

  • Draft and review: Create drafts for approval workflows before sending.
  • Automation: Automate repetitive email tasks like notifications, follow-ups, or reminders.
  • Personalization: Craft individualized messages at scale (e.g., HR announcements, marketing emails).
  • Reliability: Ensures the message is queued and sent using the secure Microsoft Graph endpoint.

Cmdlet Syntax

Send-MgUserMessage -UserId <String> -MessageId <String>

Parameters:

  • UserId: The User Principal Name (UPN) or the ID of the mailbox owner.
  • MessageId: The ID of the draft message you created earlier.

Note: The MessageId must reference a draft message. Otherwise, you will encounter an error.


Usage Examples

Example 1: 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
                                            

Example 2: 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
                                            

Example 3: 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
}
                                            

Tip: Ensure your recipients.csv file has a header column named Email with user email addresses.


Frequently Asked Questions

  • Can I send emails directly without creating a draft first?
    No. With Send-MgUserMessage, you must first create the draft using New-MgUserMessage and then send it.
  • What happens if I provide an invalid MessageId?
    You will get an error stating that the MessageId was not found or does not belong to a draft.
  • Can attachments be included?
    Yes! Attachments can be added during the draft creation step (New-MgUserMessage) by specifying the attachments property.
  • Is it possible to send emails as another user?
    Only if you have the necessary delegated or application permissions (like Mail.Send and Mail.ReadWrite scopes).

Use Cases

  • Automated meeting reminders for team members.
  • Sending follow-up emails for pending tasks.
  • Bulk notification campaigns (e.g., HR policy updates, training invitations).
  • Ticketing system notifications triggered through PowerShell.

Conclusion

Send-MgUserMessage is a fantastic cmdlet that makes it easy to send Microsoft 365 emails through a secure, programmable method. Whether you're sending single emails, automatic follow-ups, or bulk notifications, this cmdlet ensures you maintain full control over your mail-sending processes.

Start experimenting today by combining New-MgUserMessage and Send-MgUserMessage, and unlock powerful automation opportunities for your M365 environment!


Need more help automating M365 tasks? Stay tuned for more Graph PowerShell tutorials!


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