3

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

TylerH
  • 20,799
  • 66
  • 75
  • 101
Min
  • 429
  • 9
  • 25
  • 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. – Min Mar 31 '16 at 20:38

3 Answers3

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       = 'mindaugas@yahoo.com'
    To         = 'someone@domain.com'
    Subject    = 'A subject line'
    Body       = 'Mail message content goes here!'
    SmtpServer = 'smtp.mail.yahoo.com'
    Port       = 587
    UseSsl     = $true
    Credential = New-Object pscredential 'mindaugas@yahoo.com',$('P@ssW0rd!' |ConvertTo-SecureString -AsPlainText -Force)
}
Send-MailMessage @MailArgs
Mathias R. Jessen
  • 157,619
  • 12
  • 148
  • 206
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("XXXX@gmail.com");
$mail.To.Add("XXX@XXXX.com");
$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("XXXXX@gmail.com", "password");
$smtp.EnableSsl = "true";
$smtp.Send($mail);
Manoj Patil
  • 970
  • 1
  • 10
  • 19
0

This finally worked for me for SBCGlobal.net since the secure mail key at Yahoo:

    $from = "name@sbcglobal.net"
    $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 <name@sbcglobal.net> -From <name@sbcglobal.net> -Subject '<Subject>' -Body '<Message>'
LouF
  • 1
  • 1