How to Send an Email Using Windows PowerShell
Pinterest Whatsapp
Advertisement

Email is so basic that most people don’t even think about it. Open up your mail client, type a message and recipient, and hit send. Not too tough, right?

But have you ever considered alternate ways to send emails? Whether you just want to geek out and do something techy or want to send an email without getting distracted by your inbox 3 Quick Ways To Send Emails Without Getting Distracted By Your Inbox 3 Quick Ways To Send Emails Without Getting Distracted By Your Inbox You try your best to stay on task, send your email, and get out, but an hour or two later you realize, you've been sucked in by the black hole of your email client. Read More , there’s one hiding right on your Windows desktop.

How to Send an Email Using Windows PowerShell PowerShell Send Email

How to Send an Email Using PowerShell

  1. Open a PowerShell window by searching for PowerShell in the Start Menu.
  2. Use the below Gmail template to set up your email. The first lines that start with dollar signs set up variables for sending the message, while the Send-MailMessage line is the actual command:
    $From = "EmailAddress@gmail.com"
    $To = "SomeOtherAddress@whatever.com"
    $Cc = "AThirdUser@somewhere.com"
    $Attachment = "C:\users\Username\Documents\SomeTextFile.txt"
    $Subject = "Here's the Email Subject"
    $Body = "This is what I want to say"
    $SMTPServer = "smtp.gmail.com"
    $SMTPPort = "587"
    Send-MailMessage -From $From -to $To -Cc $Cc -Subject $Subject -Body $Body -SmtpServer $SMTPServer -port $SMTPPort -UseSsl -Credential (Get-Credential) -Attachments $Attachment –DeliveryNotificationOption OnSuccess
  3. If using Yahoo mail, the server is smtp.mail.yahoo.com and the port is 465. For Outlook, the server is smtp-mail.outlook.com with port 587.
  4. You can remove the Attachment and CC lines if you don’t need them. Make sure to remove them from the Send-MailMessage line too.
  5. Including –UseSsl makes sure the email sense securely. You can also include -DeliveryNotificationOption OnSuccess if you want to receive confirmation that it sent successfully.
  6. Once you issue the command, it will prompt you for your username and password thanks to(Get-Credential). Enter that, and your email is on its way!

For another geeky way to do this, check out how you can send an email with Google Sheets How to Send Email in a Google Sheet With Google Scripts How to Send Email in a Google Sheet With Google Scripts Learn how to use Google Scripts to automate Google productivity tools like Sheets and Docs and save yourself hours of time. Read More .

What do you think about this method of sending emails? What other cool ways do you know to do this? Share them with us in the comments below!

Enjoyed this article? Stay informed by joining our newsletter!

Enter your Email

Leave a Reply

Your email address will not be published. Required fields are marked *

  1. Baljeet Singh
    February 3, 2018 at 2:57 pm

    very very good and easy, expained very nicely. Thanks