How to Use New-MgUserMessage to Automate Mails?

If you're looking to automate email communication using Microsoft 365 and Graph PowerShell, you're in the right place. Whether you're sending reminders, sharing reports, or delivering status updates—New-MgUserMessage can help you craft messages programmatically and streamline your workflows.

Let’s dive into how this cmdlet works and explore some real-world examples.

What is New-MgUserMessage?

New-MgUserMessage is a Microsoft Graph PowerShell cmdlet that allows you to create an email message in a user’s mailbox. Once the draft is created, it can be sent using the Send-MgUserMessage cmdlet.

It supports plain text, HTML content, and even file attachments—making it a powerful tool for automated communication scenarios.

Why Use New-MgUserMessage?

Here are just a few reasons why you might want to use this cmdlet:

  • Send automated reports
  • Trigger reminders or alerts
  • Create pre-drafted emails for review
  • Send attachments directly via script
  • Integrate mailing into workflows or scheduled tasks

Whether you're handling internal notifications or customer-facing emails, this cmdlet simplifies the process.

Cmdlet Syntax

New-MgUserMessage -UserId <String> -BodyParameter <IMicrosoftGraphMessage>

Parameters:

  • UserId: The mailbox owner’s UPN or User ID (e.g., jane.doe@example.com)
  • BodyParameter: A hashtable containing the message details including subject, body, recipients, attachments, etc.

Usage Examples

Create a Simple Email Message

$params = @{
    subject = "Meeting Reminder"
    body = @{
        contentType = "Text"
        content = "This is a reminder for the team meeting scheduled for tomorrow at 10 AM."
    }
    toRecipients = @(
    @{
        emailAddress = @{
        address = "john.doe@example.com"
        }
    }
    )
}
                                        
New-MgUserMessage -UserId "jane.doe@example.com" -BodyParameter $params
                                        

This creates a basic plain-text message. You can send it using Send-MgUserMessage.

Create an HTML Email Message

$params = @{
    subject = "Project Update"
    body = @{
        contentType = "HTML"
        content = "<p>Dear Team</p><p>Please find the latest updates on the project.</p><p>Best Regards<br/>Jane</p>"
    }
    toRecipients = @(
                @{
                        emailAddress = @{
                            address = "team@example.com"
                        }
                }
    )
}
                                        
New-MgUserMessage -UserId "jane.doe@example.com" -BodyParameter $params

HTML formatting adds structure and branding to your emails—great for status updates and announcements.

Create an Email with Attachments

$params = @{
    subject = "Monthly Report"
    body = @{
        contentType = "Text"
        content = "Please find the attached monthly report."
    }
    toRecipients = @(
        @{
        emailAddress = @{
        address = "manager@example.com"
        }
    }
    )
    attachments = @(
        @{
            "@odata.type" = "#microsoft.graph.fileAttachment"
            name = "report.pdf"
            contentBytes = [System.Convert]::ToBase64String([System.IO.File]::ReadAllBytes("C:\Reports\report.pdf"))
        }
    )
}
                                        
New-MgUserMessage -UserId "jane.doe@example.com" -BodyParameter $params
                                        

Frequently Asked Questions

Does this cmdlet send the email automatically?

No. It only creates the message in the Drafts folder. Use Send-MgUserMessage to send it.

Can I send to multiple recipients?

Yes! Just add more recipient objects under toRecipients.

Do I need permissions?

Yes. You need Mail.Send or Mail.ReadWrite delegated/application permissions to use this cmdlet.

Use Cases

  • Automated Meeting Reminders
  • Send daily or weekly reminders to team members with just a script.

  • Report Distribution
  • Email reports to managers or stakeholders at scheduled intervals.

  • User Notifications
  • Notify users of password expiry, policy updates, or onboarding instructions.

  • Workflow Integration
  • Combine with logic apps, flows, or scripts to integrate mailing into your existing systems.

Conclusion

New-MgUserMessage unlocks the potential of automating email creation within Microsoft 365. Whether you're sending alerts, scheduling reminders, or sharing important documents—this cmdlet helps bring consistency and automation to your communication efforts.

Pair it with Send-MgUserMessage and watch your productivity soar.

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