Send email using powershell

From Luniwiki
Jump to: navigation, search
PS C:\Users\dany\Desktop> cat .\Testsendemail.ps1
$smtpFrom = “do-not-reply@luniel.com”
$smtpTo = “example@otherdomain.com”
$messageSubject = “test from do-not-reply at luniel.com”
$messageBody = “This is a test sending an email from email do-not-reply at luniel.com”
$smtpServer = “smtp.luniel.com”
$smtp = New-Object Net.Mail.SmtpClient($SmtpServer, 587)
$smtp.EnableSsl = $true
$smtp.Credentials = New-Object System.Net.NetworkCredential("do-not-reply@luniel.com", "<PASSWORD>");
$smtp.Send($smtpFrom , $smtpTo, $messageSubject, $messageBody)
PS C:\Users\dany\Desktop>
PS C:\Users\dany\Desktop> .\Testsendemail.ps1

References

Daniel Simao 09:47, 3 April 2020 (EDT)