powershell - Send-MailMessage

sample code

$from = "xxxx@gmail.com"
$to = "xxxx@gmail.com"
$cc = "xxxx@gmail.com"
$smtp = "smtp.gmail.com"
$port = "587"
$subject = "メール件名"
$user = "xxxx@gmail.com"
$password = "xxxxxxxxxxxxxxxxx"

$pass = ConvertTo-SecureString $password -AsPlainText -Force
$credential = New-Object System.Management.Automation.PSCredential $user, $pass

[string]$body = @()
$body += "あいさつ1`r`n"
$body += "あいさつ2`r`n"
$body += "あいさつ3`r`n"

try {

    Send-MailMessage -From $from `
                     -to $to `
                     -Cc $cc `
                     -SmtpServer $smtp `
                     -port $port `
                     -Subject $subject `
                     -Body $body `
                     -Credential $credential `
                     -UseSsl `
                     -Encoding ([System.Text.Encoding]::UTF8)
}
catch {
    Write-Error $Error[0]
}