Search code examples
powershellsmtp

How to send an email from yahoo SMTP server with PowerShell?


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


Solution

  • 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