Skip to content

Instantly share code, notes, and snippets.

@Nora-Ballard
Created April 24, 2014 03:19
Show Gist options
  • Select an option

  • Save Nora-Ballard/11240319 to your computer and use it in GitHub Desktop.

Select an option

Save Nora-Ballard/11240319 to your computer and use it in GitHub Desktop.
Create new email in the default mail client, and optionally include an attachment.
function Invoke-MailTo {
param(
[OutputType([bool])]
[Parameter(Mandatory)]
[ValidateNotNullOrEmpty()]
[string]$To,
[Parameter(Mandatory)]
[string]$Subject,
[Parameter(Mandatory)]
[string]$Body,
[Parameter()]
[ValidateScript({Test-Path $_})]
$Attachment = ""
)
if ($Attachment.FullName) {$Attachment = $Attachment.FullName}
$MailToURL = 'mailto:{0}?subject={1}&body={2}&attach={3}' -f $To,$Subject,$Body,$Attachment
try { Invoke-Expression $("start '{0}'" -f $MailToURL) ; Write-Output $true }
catch { $false }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment