Send Email from Windows Computer using powershell script

in some cases, you might need to test your email configurations before you insert into application configs. here is a sample script you can use for test smtp emails from your windows computer,


 # Define the email properties
$From = "from@address.net"
$To = "to@address.com"
$Subject = "Test Mail From Windows"
$Body = "This is the body of the email with content"
 
# Define the SMTP server details
$SMTPServer = "email.server.com.com"
$SMTPPort = 587
$SMTPUsername = "SMTPUSERNAME"
$SMTPPassword = "SMTPPASSWORD"
 
# Create the email object
$Email = New-Object System.Net.Mail.MailMessage($From, $To, $Subject, $Body)
 
# Set the SMTP client details and send the email
$SMTPClient = New-Object System.Net.Mail.SmtpClient($SMTPServer, $SMTPPort)
$SMTPClient.EnableSsl = $true
$SMTPClient.Credentials = New-Object System.Net.NetworkCredential($SMTPUsername, $SMTPPassword)
$SMTPClient.Send($Email) 


all you need is to save this fine as mail.ps1 and run from from powershell.

Rasika Preethiraj

A technophile at icrony since 2012, In a quest to programmatic automations for scaled organisations through the use of python, php, autoit and machine learning


Comments


Post a Comment



Trending

Latest Posts

Tags

Newsletter

Subscribe to our newsletter for good news, sent out every month.