How To Send Email From Windows Command Line

Channel: Linux
Abstract: $SMTPClient = New-Object Net.Mail.SmtpClient($SMTPServerThis tutorial will help you to send an email from the Windows command line via remote SMTP ser

This tutorial will help you to send an email from the Windows command line via remote SMTP server. You need SMTP server details for sending email from Windows PowerShell command.

Send Email from Windows PowerShell

Once you have SMTP details, open Windows PowerShell and execute the following commands one by one. You need to change the orange highlighted values with the appropriate values as per your setup.

$EmailFrom = 「[email protected]」
$EmailTo = 「[email protected]」
$Subject = 「Email Subject Here」
$Body = 「This is mail body」
$SMTPServer = 「smtp.gmail.com」
$SMTPClient = New-Object Net.Mail.SmtpClient($SMTPServer, 587)
$SMTPClient.EnableSsl = $true
$SMTPClient.Credentials = New-Object System.Net.NetworkCredential(「SMTP Username」, 「SMTP Password」);
$SMTPClient.Send($EmailFrom, $EmailTo, $Subject, $Body)

This will send email to the recipient address via defined remote SMTP server. You can also write this in a PowerShell script and execute.

Ref From: tecadmin

Related articles