How to send an email with powershell

Viewed 37

How the heck do you send an email with powershell? I have the following code:

$Username = "test@yahoo.com"
$Password = "testpassword"
 
$SecurePassword = $Password | ConvertTo-SecureString -AsPlainText -Force
$Credentials = New-Object System.Management.Automation.PSCredential -ArgumentList $Username, $SecurePassword
 
$RcptTo = "somebody@mailserver.com"
$Subject = "Yahoo Test"
$Body = "This is a test message"
Send-MailMessage -From $Username -To $RcptTo -Subject $Subject -Body $Body -SmtpServer smtp.mail.yahoo.com -Port 587 -UseSsl -Credential $Credentials

But am receiving the following error:

Send-MailMessage : Unable to read data from the transport connection: net_io_connectionclosed.
1 Answers
Related