cls; function Send-EasyEmail([String]$subject,[String]$body){ #设置基本信息 $from="xxx@gmail.com" $to='xxx@163.com' $SMTPServer="smtp.gmail.com" #创建email对象 $SMTPClient= New-Object Net.Mail.SmtpClient($SMTPServer,25) #使用 ssl协议 $SMTPClient.EnableSsl=$true $SMTPClient.Credentials =New-Object System.Net.NetworkCredential("xxx","w_13810400383"); $SMTPClient.Send($from,$to,$subject,$body) } Send-EasyEmail -subject "标题" -body "内容" #推荐使用下面这个 cls $ss=ConvertTo-SecureString -String "w_13810400383" -AsPlainText -force $ss|Write-Host $cre= New-Object System.Management.Automation.PSCredential("xxx@gmail.com",$ss) Send-MailMessage -SmtpServer "smtp.gmail.com" -UseSsl -Port 25 -Body "11" -Subject "s" -To "xxx@qq.com" -From "xxx@gmail.com" -Credential $cre