New-MgUserMessage Vs. Send-MgUserMail

Microsoft Graph PowerShell offers powerful cmdlets that allow administrators to automate and manage various tasks related to email messaging. Among these cmdlets, New-MgUserMessage and Send-MgUserMail are essential tools for creating and sending emails programmatically. While they might seem similar at first glance, each serves a distinct purpose and is suited for different scenarios.


New-MgUserMessage

Purpose:

The New-MgUserMessage cmdlet is used to create a new email message in the specified user's mailbox. This cmdlet allows you to draft the email without sending it immediately.

Key Features:

  • Create Drafts: You can create an email draft that can be saved and later modified or sent.
  • Detailed Composition: Allows you to specify various properties of the message such as subject, body, recipients, and attachments.
  • Complex Messages: Supports creating messages with rich text, HTML, and multiple recipients (To, Cc, Bcc).

Example Usage:

$params = @{
    Subject = "Project Update"
    Body = @{
        ContentType = "HTML"
        Content = "<p>Hello Team</p><p>Please find the project update attached.</p>""
    }
    ToRecipients = @(
        @{
            EmailAddress = @{
                Address = "user@example.com"
            }
        }
    )
}
New-MgUserMessage -UserId "user@domain.com" -BodyParameter $params

Send-MgUserMail

Purpose:

The Send-MgUserMail cmdlet is used to send an email message from the specified user's mailbox. This cmdlet combines the creation and sending of the email into a single action.

Key Features:

  • Send Immediately: Directly sends the email without creating a draft.
  • Simplified Process: Ideal for scenarios where you need to send an email quickly without the need for saving drafts or making multiple edits.
  • Basic Message Composition: While it allows for specifying recipients, subject, body, and attachments, it is typically used for straightforward email sending.

Example Usage:

$params = @{
    Message = @{
        Subject = "Meeting Reminder"
        Body = @{
            ContentType = "Text"
            Content = "This is a reminder for our upcoming meeting."
        }
        ToRecipients = @(
            @{
                EmailAddress = @{
                    Address = "user@example.com"
                }
            }
        )
    }
    SaveToSentItems = $true
}
Send-MgUserMail -UserId "user@domain.com" -BodyParameter $params

Summary of Differences

Action:

  • New-MgUserMessage: Creates a draft message in the user's mailbox.
  • Send-MgUserMail: Sends the email immediately.

Usage Scenario:

  • New-MgUserMessage: When you need to draft and possibly modify an email before sending it.
  • Send-MgUserMail: When you need to send an email right away without the need for drafts.

Flexibility:

  • New-MgUserMessage: Provides more flexibility in composing complex emails with rich text, HTML, and multiple attachments.
  • Send-MgUserMail: More streamlined for sending simple and immediate messages.

Related Articles:

Using Get-MgDirectoryRole in Graph PowerShell
Using Get-MgUserLicenseDetail in Graph PowerShell
Using Find-GraphMgCommand in Graph PowerShell
Connect to Microsoft 365 Using PowerShell
How to Create Bulk Users in Office 365 Using Graph PowerShell?
Create Microsoft 365 Group Using Microsoft Graph PowerShell
Block Microsoft 365 User Using Microsoft Graph PowerShell
Assign Microsoft 365 License Using Graph PowerShell
Microsoft 365 User Management Using Graph PowerShell
Checking Group Membership in Microsoft 365
Bulk Assign Microsoft 365 License
Find Inactive Users in Microsoft 365
Using Powershell Graph Search Query
Using Powershell Graph Filter Query
Using Where-Object In Graph PowerShell
Using Expand Property In Graph PowerShell
Using Select Object In Graph PowerShell
Using -Contains Operator In Graph PowerShell
Add User to Multiple Microsoft 365 Groups Using Graph PowerShell
Get Microsoft 365 User Location Using Graph PowerShell
Import Microsoft 365 Groups from CSV File Using Graph PowerShell
Microsoft 365 Group User Import Using Graph PowerShell

© m365corner.com. All Rights Reserved. Design by HTML Codex