Scripts/Send-Mail.ps1
$Params = @{ To = "you@somewhere.com" From = "me@somewhere.com" Subject = "Test $(Get-Date -Format "yyyy-MM-dd HH:mm")" Body = $Body BodyAsHtml = $true SmtpServer = "mail.local" } $MailSplit = $Params.To -split "@" $DnsResolve = Resolve-DnsName $MailSplit[1] -Type MX $SmtpServer = $DnsResolve[0].NameExchange $SmtpServer $Params.SmtpServer = $SmtpServer $Params Send-MailMessage @Params # Mail via Graph $Params = @{ Message = @{ Subject = "Meet for lunch?" Body = @{ ContentType = "Text" Content = "The new cafeteria is open." } ToRecipients = @( @{ EmailAddress = @{ Address = "you@somewhere.com" } } ) } SaveToSentItems = "false" } Send-MgUserMail -UserId "someone@me.com" -BodyParameter $Params |