Send an e-mail via Powershell script using Send-MailMessage

$password = ConvertTo-SecureString 'YourSmtpAccountPassword' -AsPlainText -Force
$credential = New-Object System.Management.Automation.PSCredential ('YourSmtpUsername', $password)
$smtpServer = "smtp.yourdomain.com"
$smtpPort = 587
 
$from = "sender@yourdomain.com"
$to = "recipient@yourdomain.com"
$subject = "Your e-mail subject"
$body = "Your e-mail text"
 
Send-MailMessage -SmtpServer $smtpServer -Port $smtpPort -UseSsl -From $from -To $to -Subject $subject -Body $body -Credential (Get-Credential $credential)

In order to run that as a powershell script you may need to run (at least) “Set-ExecutionPolicy RemoteSigned” in a privileged powershell. The script is configured to use a secure connection to your SMTP server (SSL/TLS) on port 587.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.