Powershell Script to Send Email

Tags: powershell, email

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

source: http://stackoverflow.com/questions/36342884/how-to-send-an-email-from-yahoo-smtp-server-with-powershell/36343788#36343788

No Comments

You must log on to comment.