In Windows there is no way to natively send mail from the Command Prompt, but because PowerShell allows you to use the underlying .Net Framework, you can easily create and send an  e-mail from the command line.

Note: I have uploaded a sample over here, due to many requests.

Sending Email From PowerShell

Note: We decided to use the GMail SMTP Servers for this article, that means you will need a GMail account to send mail using the provided code. However, you could easily hack my script to work with any SMTP Server should you want to.

The first thing you need to do is fire up PowerShell.

It’s pretty easy to send an e-mail from PowerShell, all you need to do is copy the template we provided and change some of the details.

$EmailFrom = “”

$EmailTo = “”

$Subject = “The subject of your email”

$Body = “What do you want your email to say”

$SMTPServer = “”

$SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, 587)

$SMTPClient.EnableSsl = $true

$SMTPClient.Credentials = New-Object System.Net.NetworkCredential(“usr”, “pass”);

$SMTPClient.Send($EmailFrom, $EmailTo, $Subject, $Body)

You will need to change the following:

  • $EmailFrom = Your GMail address.
  • $EmailTo = The recipient’s email address.
  • $Subject = What you want the subject of the mail to say.
  • $Body = What you want the main part of the mail to say.
  • usr = You will need to replace this with your GMail username.
  • pass = You will need to replace this with your GMail password.

Below is an example of me sending mail to myself.

Note: For obvious reasons, I removed GMail credentials from the screenshot.

That’s all there is to it.

Profile Photo for Taylor Gibb Taylor Gibb
Taylor Gibb is a professional software developer with nearly a decade of experience. He served as Microsoft Regional Director in South Africa for two years and has received multiple Microsoft MVP (Most Valued Professional) awards. He currently works in R&D at Derivco International.
Read Full Bio »