How to send Email with Windows PowerShell

Sending email is a simple task that most people can do. Open the email application, enter the message, the recipient and press the send button. Operation is not too difficult, right? But have you ever considered other ways to email? One way to send email without going to the mail application is to send a message using Windows PowerShell.

Sending email is a simple task that most people can do. Open the email application, enter the message, the recipient and press the send button. Operation is not too difficult, right? But have you ever considered other ways to email? One way to send email without going to the mail application is to send a message using Windows PowerShell.

How to send email using PowerShell

Step 1: Open PowerShell window by searching PowerShell in the Start menu.

Step 2: Use the Gmail form below to set up email. The first line begins with the dollar sign that sets the variables to send the message, while the Send-MailMessage line is the actual command:

How to send Email with Windows PowerShell Picture 1How to send Email with Windows PowerShell Picture 1

$ From = "EmailAddress@gmail.com"
$ To = "SomeOtherAddress@whatever.com"
$ Cc = "AThirdUser@somewhere.com"
$ Attachment = "C: usersUsernameDocumentsSomeTextFile.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

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

Step 4: You can remove Attachment and CC if you don't need them and also delete them in the Send-MailMessage line.

Step 5: Use -UseSsl to make sure email is safe. You can also add -DeliveryNotificationOption OnSuccess if you want to receive confirmation that the message has been sent successfully.

Step 6: When running the command, it will prompt you to enter a username and password (Get-Credential) . Enter this information and your email will be sent.

This is another way to send an email, see the Guide to Email Automatically in Google Sheet with Google Script.

I wish you all success!

See more:

  1. Send email with another Gmail account
  2. Quickly view email sender information on Gmail with Gmail Sender Icons
  3. How to send email to self-destruct within 5 minutes on Gmail
4.2 ★ | 14 Vote