How to send an email from yahoo SMTP server with PowerShell v3? Authentication is required.
3 Answers
Send-MailMessage has a -Credential parameter that takes a pscredential object. I would use a hashtable to store and splat the connection arguments:
$MailArgs = @{ From = '[email protected]' To = '[email protected]' Subject = 'A subject line' Body = 'Mail message content goes here!' SmtpServer = 'smtp.mail.yahoo.com' Port = 587 UseSsl = $true Credential = New-Object pscredential '[email protected]',$('P@ssW0rd!' |ConvertTo-SecureString -AsPlainText -Force) } Send-MailMessage @MailArgs Comments
This finally worked for me for SBCGlobal.net since the secure mail key at Yahoo:
$from = "[email protected]" $secpass = ConvertTo-SecureString "<SecureMailKeyPassword>" -AsPlainText -Force $mycred = New-Object System.Management.Automation.PSCredential ($from, $secpass) Send-MailMessage -SmtpServer 'smtp.mail.yahoo.com' -UseSsl -Port 587 -Credential $mycred -To <[email protected]> -From <[email protected]> -Subject '<Subject>' -Body '<Message>' Comments
in case somebody looking for google smtp using MailMessage
[System.Reflection.Assembly]::LoadWithPartialName("System.Net") [System.Reflection.Assembly]::LoadWithPartialName("System.Net.Mail") [System.Reflection.Assembly]::LoadWithPartialName("System.Net.Mail.MailMessage") $mail = New-Object System.Net.Mail.MailMessage $mail.From = New-Object System.Net.Mail.MailAddress("[email protected]"); $mail.To.Add("[email protected]"); $mail.Subject = "Place Subject of email here"; $mail.Body = "Place body content here"; $smtp = New-Object System.Net.Mail.SmtpClient("smtp.gmail.com"); $smtp.Port = "587"; $smtp.Credentials = New-Object System.Net.NetworkCredential("[email protected]", "password"); $smtp.EnableSsl = "true"; $smtp.Send($mail);