Quick answer: connect with Connect-MgGraph -Scopes "Mail.Send", build a hashtable with a message (subject, body, toRecipients) and run Send-MgUserMail -UserId you@contoso.com -BodyParameter $params. A silent return means Microsoft Graph accepted the message (HTTP 202). To send from scripts with no one signed in, use an app registration with the Mail.Send application permission.
What is Send-MgUserMail?
Send-MgUserMail is the Microsoft Graph PowerShell cmdlet for the user: sendMail API. It sends a message from a Microsoft 365 mailbox in one call. It lives in the Microsoft.Graph.Users.Actions module and replaces scripts built on the retired Send-MailMessage and SMTP basic auth.
What permissions does it need?
| Sign-in type | Permission | Sends as |
|---|---|---|
| Delegated (work or school) | Mail.Send | The signed-in user |
| Delegated, other mailboxes | Mail.Send.Shared | A shared mailbox or user you have Send As or Send on Behalf rights for |
| Delegated (personal account) | Mail.Send | The signed-in user |
| Application (app-only) | Mail.Send | Any mailbox in the tenant |
Application Mail.Send reaches every mailbox by default. Limit it to the mailboxes your script needs with RBAC for Applications in Exchange Online.
How do I install and connect?
Install-Module Microsoft.Graph.Users.Actions -Scope CurrentUser
# Interactive, as yourself
Connect-MgGraph -Scopes "Mail.Send"
# Unattended, as an app registration with a certificate
Connect-MgGraph -ClientId $appId -TenantId $tenantId -CertificateThumbprint $thumb
See using Connect-MgGraph for the sign-in options.
How do I send a basic email?
$params = @{
message = @{
subject = "Meet for lunch?"
body = @{
contentType = "Text"
content = "The new cafeteria is open."
}
toRecipients = @(
@{ emailAddress = @{ address = "frannis@contoso.com" } }
)
ccRecipients = @(
@{ emailAddress = @{ address = "danas@contoso.com" } }
)
}
saveToSentItems = $false
}
Send-MgUserMail -UserId "adele@contoso.com" -BodyParameter $params
-UserId takes a user ID or UPN. It's the mailbox the email comes from. saveToSentItems defaults to true, so leave it out unless you want no copy in Sent Items.
How do I send HTML or to several people?
Set contentType = "HTML" and put markup in content. Add one entry per person to toRecipients, ccRecipients or bccRecipients:
$to = "a@contoso.com","b@contoso.com" | ForEach-Object {
@{ emailAddress = @{ address = $_ } }
}
$params = @{
message = @{
subject = "Weekly report"
body = @{ contentType = "HTML"; content = "<h1>Report</h1><p>See attached.</p>" }
toRecipients = @($to)
}
}
How do I add an attachment?
Attachments go in the same call as base64 contentBytes:
$bytes = [Convert]::ToBase64String([IO.File]::ReadAllBytes("C:\Reports\report.csv"))
$params.message.attachments = @(
@{
"@odata.type" = "#microsoft.graph.fileAttachment"
name = "report.csv"
contentType = "text/csv"
contentBytes = $bytes
}
)
Send-MgUserMail -UserId "reports@contoso.com" -BodyParameter $params
Files under 3 MB fit in one request. Larger files need a draft message and an upload session.
Does a silent return mean the email was delivered?
No. Send-MgUserMail returns nothing on success because the API answers 202 Accepted. That means Graph took the message, not that Exchange delivered it. Delivery is still subject to Exchange Online sending limits and throttling. Check message trace if a recipient says nothing arrived.
Troubleshooting
| Symptom | Cause | Fix |
|---|---|---|
| "Send-MgUserMail is not recognized" | Module not installed | Install-Module Microsoft.Graph.Users.Actions |
| 403 ErrorAccessDenied | Missing Mail.Send consent, or sending as someone else with a delegated token | Reconnect with -Scopes "Mail.Send"; use Mail.Send.Shared or app-only for other mailboxes |
| 404 ResourceNotFound | -UserId has no Exchange Online mailbox |
Use the UPN of a licensed or shared mailbox |
| Cannot convert or bind parameter | Hashtable key typo, such as Email Address |
Use emailAddress, toRecipients, contentType exactly |
| 400 "Invalid base64 string for MIME content" | Bad MIME body | Base64-encode the whole MIME message |
| No error, no email | Accepted, then blocked or throttled | Check message trace and sending limits |
Summary
Connect-MgGraph -Scopes "Mail.Send", thenSend-MgUserMail -UserId <upn> -BodyParameter $params.- App-only Mail.Send works for unattended scripts; scope it with RBAC for Applications.
- Messages save to Sent Items unless
saveToSentItems = $false. - Attachments under 3 MB go inline as base64.
- No output means accepted, not delivered.
Related: Connect-MgGraph, Get-MgUser, Get-MgGroupMember.
Meeting Room 365 turns any iPad or Android tablet into a room display for Exchange and Microsoft 365 calendars. See the features or pricing: $9 a display a month.