Powershell 发送邮件代码

$pw = import-csv D:pw.csv
$user = "junjianyang@focuswin.cn"
$PWord = ConvertTo-SecureString –String "password" –AsPlainText -Force
$mycreds = New-Object –TypeName System.Management.Automation.PSCredential –ArgumentList $User, $PWord
$pw | ForEach-Object {Send-MailMessage -Encoding utf8 -To $_.to -From junjianyang@focuswin.cn -Subject "Test测试" -Body ("密码是:" + $_.pw) -Credential $mycreds -SmtpServer smtp.office365.com -DeliveryNotificationOption Never -BodyAsHtml -UseSsl -port 587}

国际版的office 365 

原文地址:https://www.cnblogs.com/junjiany/p/9105233.html