3

How to send an email from yahoo SMTP server with PowerShell v3? Authentication is required.

1
  • PowerShell has Send-MailMessage method. It works well if you have an SMTP server that does not require authentication. Well, it does not work for me. Commented Mar 31, 2016 at 20:38

3 Answers 3

7

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 
Sign up to request clarification or add additional context in comments.

Comments

0

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

0

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); 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.