Home > PowerShell, Tips > send emails via gmail account using powershell

send emails via gmail account using powershell

January 13th, 2010 Leave a comment Go to comments

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 http://techibee.com’)

Command to execute:

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

Happy Learning..,
Sitaram Pamarthi

Other posts