Tech News Today
  • Hardware
    • Motherboards
    • CPUs
    • Graphic Cards
    • RAM
    • SSDs
    • Computer Cases
    • Monitors
    • Peripherals
    • Power Supply Unit
    • PC Builds
    • Computer Tips
  • Software
  • Operating System
    • Windows
    • Mac
    • Linux
  • Gaming
  • Mobile
  • Console
  • More
    • Internet
    • Networking
    • Security
    • Buyer’s Guide
    • Gadgets
    • Laptops
    • Reviews
    • How To
    • News
Facebook Twitter Instagram
Tech News Today
  • Hardware
    • Motherboards
    • CPUs
    • Graphic Cards
    • RAM
    • SSDs
    • Computer Cases
    • Monitors
    • Peripherals
    • Power Supply Unit
    • PC Builds
    • Computer Tips
  • Software
  • Operating System
    • Windows
    • Mac
    • Linux
  • Gaming
  • Mobile
  • Console
  • More
    • Internet
    • Networking
    • Security
    • Buyer’s Guide
    • Gadgets
    • Laptops
    • Reviews
    • How To
    • News
Tech News Today
Home»Windows»How To Send Emails From Powershell

How To Send Emails From Powershell

nishantBy nishantDecember 12, 2022
PowerShell send mail message

Powershell is a powerful Integrated Scripting Environment (ISE) that can be used to write and debug scripts. This scripting environment can perform a wide range of functions, including sending emails using scripts and cmdlets. This can help the system administrators in automating the process of sending bulk emails.  

To use PowerShell to send emails, users must specify the parameters, including the SMTP server that they want to use for pushing the mail. All these whereabouts are discussed in today’s article.

Parameters You Can Use To Send Email From PowerShell

These are some major parameters you can use to send Emails using PowerShell.

  • -From : Email address of the sender 
  • -To : Email Address of the mail Receiver
  • -Cc: Email address of the recipient who gets the Email message’s Carbon Copy
  • -Attachments : File path of the attachment that is to be sent with the Email
  • -Subject : Email’s subject
  • -Body: Body (Main message) of the Email
  • -Credentials : SMTP server login credentials. This is used to authenticate the SMTP server
  • -SmtpServer : Address of the SMTP server ( For instance: smtp.gmail.com)
  • -Port : Port on the SMTP server 
  • -Use Ssl: Use Secure Sockets Layer Protocol.

Send Emails From Powershell

The most common method to send e-mails using PowerShell is by using the Send-MailMessage cmdlet. There are other popular tools like system.netmail API, EASendMAil component, and Microsoft Graph API. 

The Send-MailMessage cmdlet, even after being labeled obsolete by Microsoft, still is the most convenient option for sending emails from PowerShell. 

  • Here is a general syntax for using this cmdlet to send an E-mail.

    Send-MailMessage -From "Sender Email" -To Recipients email" -Credentials (Get-Credential) -SmtpServer "SMPT server address"

    For instance,

    Send-MailMessage -From "yosar72796@covbase.com" -To "tnt@tnt.com" -Subject “E-mail's Subject” -Body “Main message of the E-mail” -Credentials (Get-Credential) -SmtpServer "smtp.outlook.com"Send mail message

    Most of the time, you can use these cmdlets without the -Credentials parameter. However, if the server restricts you by giving a message saying,” Client was not authenticated,” then try using the parameter.

  • If the E-mail is to be sent to multiple users,

    Send-MailMessage -From "yosar72796@covbase.com" -To "tnt@tnt.com", "hr@tnt.com" -Credentials (Get-Credential) -SmtpServer "smtp.outlook.com"Send mail message credentials

  • If you want to send the email with an attachment, you can add -Attachmentparameter.
    Send-MailMessage -From "Nishant@tnt.com" -To "tnt@tnt.com", "hr@tnt.com" -Attachment "C:\temp\Some random file.txt" -Credentials (Get-Credential) -SmtpServer "smtp.outlook.com"Add attachment
  • To add CC, use the parameter -CC “E-mail receiving the copy of the mail” in the cmdlet. 

Note: You can even use the value $PSEmailServer, as the SMTP setting instead of the Smtp-Server. This is the default SMTP configuration on Powershell. 

Send Email from PowerShell with Gmail SMTP

Before May 2022, in order to use Gmail SMTP to send email from PowerShell, users had to first Enable the less secure apps from Google’s security control panel. 

After this feature was removed by Google, to use the Google SMPT server, users have to disable the two-factor authentication on their Gmail account, create app passwords, and then use those credentials in the PowerShell code.

Once You have set up the app password, you can use the cmdlets to send the E-mail. To use the Gmail SMPT, you must also have SSL enabled. All the required parameters  to use the Gmail SMTP for sending an E-mail are used in this script: 

$EmailFrom = "Nishant@gmail.com" $EmailTo = "tnt@tnt.com" $Subject = "Email Subject" $Body = "Main Message." $SMTPServer = "smtp.gmail.com" $SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, 587) $SMTPClient.EnableSsl = $true $SMTPClient.Credentials = New-Object System.Net.NetworkCredential("username", "password"); $SMTPClient.Send($EmailFrom, $EmailTo, $Subject, $Body)

Using Gmail SMTP

Here is the list of SMTP servers you can use, along with their address and Ports. 

NameSMTP Server Address
Port
Gmail smtp.gmail.com587
Outlook.comsmtp.mail.outlook.com587
Yahoosmtp.mail.yahoo.com587
AOLsmtp.mail.me.com587
AOLsmtp.aol.com465
how-to
nishant

Nishant is an enthusiast who loves writing about technology. He also is heavily invested in keeping himself updated about the latest happenings in the tech world. At Tech News Today, he covers Operating Systems, how-to-topics, and Fixes.

Related Posts

how to make cursor bigger

How to Make Cursor Bigger

February 3, 2023
enable secure boot msi bios

How to Enable Secure Boot on MSI Motherboard

February 3, 2023
how to add device to microsoft account

How to Add Device to Microsoft Account

February 2, 2023
how to delete win backup files

How to Delete Backup Files on Windows

January 29, 2023
how to reset password on hp laptop

How to Reset Password on HP Laptop

January 30, 2023
Reset BIOS password

4 Ways to Reset BIOS Password

January 28, 2023
Add A Comment

Leave A Reply Cancel Reply

Latest Posts
usb a vs usb c

USB A Vs USB C – What’s the Difference?

January 31, 2023
how long does a cmos battery last

How Long Does a CMOS Battery Last

January 25, 2023
thunderbolt vs usb c

Thunderbolt Vs USB C: What’s the Difference

January 25, 2023
You may also like
Razer Mouse Not Working

Razer Mouse Not Working? Here’re 9 Ways to Fix It

February 3, 2023
how to make cursor bigger

How to Make Cursor Bigger

February 3, 2023
surface-screen-flickering

Why is My Surface Screen Flickering? 6 Ways to Fix It

February 3, 2023
Recommended
Cookie Clicker Garden Guide

Cookie Clicker Garden Guide to Unlocking Every Seed

September 26, 2021
monitor no signal

Computer Turns On But Monitor Says No Signal (9 Ways To Fix)

November 10, 2022
Facebook Twitter Pinterest
  • Home
  • About Us
  • Our Team
  • Editorial Guidelines
  • Privacy Policy
  • Affiliate Disclosure
© 2023 TechNewsToday.

Type above and press Enter to search. Press Esc to cancel.