Techibee.com

send emails via gmail account using powershell

Copy the below powershell code into a file(say send-via-gmail.ps1) and execute it from command line.

$SmtpClient = new-object system.net.mail.smtpClient
$smtpclient.Host = ‘smtp.gmail.com’
$smtpclient.Port = 587
$smtpclient.EnableSsl = $true
$smtpClient.Credentials = [Net.NetworkCredential](Get-Credential GmailUserID)
$smtpclient.Send(‘GmailUserID@gmail.com’,$args[0] ,’test subject’, ‘The mail is sent via gmail using the powershell script grabbed from https://techibee.com’)

Command to execute:

[PS]C:>.send-via-email.ps1 toemailid@todomain.com

Happy Learning..,
Sitaram Pamarthi

Exit mobile version