X
X
The Best Tech Newsletter Anywhere

Join 250,000 subscribers and get a daily digest of news, geek trivia, and our feature articles.

How to Send Email From the Command Line in Windows (Without Extra Software)

image

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.

image

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 = “yourgmailadress@gmail.com”

$EmailTo = “destination@somedomain.com”

$Subject = “The subject of your email”

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

$SMTPServer = “smtp.gmail.com”

$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.

image

That’s all there is to it.

image

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 »

The above article may contain affiliate links, which help support How-To Geek.
How-To Geek is where you turn when you want experts to explain technology. Since we launched in 2006, our articles have been read more than 1 billion times. Want to know more?

x

The Best Tech Newsletter Anywhere

Join 250,000 subscribers and get a daily digest of news, comics, trivia, reviews, and more.