Kaffeeundcode
Script Library
PowerShell 01.06.2026

Script Workspace

Send Mail

Review the purpose, inspect the code, then test it safely in your own tenant.

91_Send-Mail.ps1

<#
.SYNOPSIS
    Verschickt eine E-Mail (via Graph).
    
.DESCRIPTION
    Sendet eine Mail aus dem Postfach des angemeldeten Users.
    Erfordert die Berechtigung 'Mail.Send'.

.NOTES
    File Name: 91_Send-Mail.ps1
    Author: Mattia Cirillo
    Version: 1.0
#>

param (
    [string]$To,
    [string]$Subject,
    [string]$Body
)

Connect-MgGraph -Scopes "Mail.Send"

$Message = @{
    subject = $Subject
    body = @{ contentType = "Text"; content = $Body }
    toRecipients = @(@{ emailAddress = @{ address = $To } })
}

Send-MgUserMail -UserId (Get-MgContext).Account -Message $Message
Write-Host "Mail gesendet."