• Home
  • Insurance
  • Banking
  • Loans
  • Remitance
  • About us
Facebook Twitter Instagram
  • links
Biz Assurance
Subscribe
  • Home
  • Insurance
  • Banking
  • Loans
  • Remitance
  • About us
Biz Assurance
Home»Tech»PowerShell Syntax for Send-Mailmessage – Email to Multiple Recipients
Tech

PowerShell Syntax for Send-Mailmessage – Email to Multiple Recipients

Alicia CormieBy Alicia CormieNo Comments2 Mins Read
Facebook Twitter WhatsApp
Share
Facebook Twitter LinkedIn WhatsApp

With so many great features and functions, PowerShell also offers a feature to send emails. This feature is tremendously awesome and useful to increase productivity. Emails can be sent to single and multiple recipients. For this purpose, use the “Send-MailMessage” cmdlet in PowerShell to send an email. Moreover, this cmdlet uses several parameters to add various features while sending an email. Many users are complaining that when they send an email to multiple recipients, the email gets sent to only one recipient.

This post will elaborate on a method to resolve the mentioned query.

PowerShell Email Syntax for Sending to Multiple Recipients

An email can be sent to multiple recipients by creating an array of strings and adding multiple emails within inverted commas, separated by commas. For instance, overview the given example code.

Syntax

Here is the required syntax:

$EmailFrom = “Sender@gmail.com”
$EmailTo = “user1@gmail.com”, “user2@gmail.com”, “user3@gmail.com”
$Subject = “Email Subject”
$Body = “Email Body”
Send-MailMessage -from “$EmailFrom“ -to $EmailTo -subject “$Subject“ -body “$Body“

In the above code:

  • First of all, create an email string of one email and assign it to the “$EmailFrom” variable.
  • After that, create an array of strings containing emails within inverted commas separated by commas, and that array is assigned to a “$EmailTo” variable.
  • Then, create an email subject within inverted commas and assign it to the “$Subject” variable.
  • Moving forward, define a body string within inverted commas and save its value to the “$Body” variable.
  • Finally, use the “Send-MailMessage” cmdlet in PowerShell to send an email.
  • After that, utilize the “-from” parameter and assign the “$EmailFrom” to add the sender’s email address.
  • The “-to” parameter with the “$EmailTo” variable is utilized for specifying multiple recipients.
  • After that, use the “-subject” parameter and assign the “$Subject” variable to add the email subject.
  • Finally, use the “-body” parameter and assign the “$Body” variable to add the email body.

That was all about the syntax for sending mail to multiple recipients.

Conclusion

The email can be sent to multiple recipients by creating an array of strings and adding emails within inverted commas separated by commas. Finally, assign the array to a variable. After that, assign the array assigned variable to the “-to” parameter to send emails to multiple recipients. This post has discussed the procedure to resolve the stated query.

Share. Facebook Twitter Pinterest LinkedIn Tumblr Email
Previous ArticleJavaScript Regular Expression Email Validation
Next Article Secure String PowerShell

Related Posts

How to Fix “Not connected – No connections are available” Error in Windows

How to Fix “Blurry Font Problem” in Windows 10

How to Fix “Can’t create new folder” in Windows 10

Add A Comment

Leave A Reply Cancel Reply

Does Texas Lawmaker Ted Cruz Really Not Consider El Paso To Be A Border City?

A Canadian Festival Features Harry Styles And Doja Cat… Except It Appears To Be Fake And Has Made Thousands In Ticket Sales

Jimmy Kimmel, The Slap, And Crisis Response Teams: Your 2023 Oscars Drinking Game

Bad Bunny Will Be One Of The Final ‘Carpool Karaoke’ Guests Before James Corden’s ‘The Late Late Show’ Ends

  • Homepage
  • Sitemap
© 2023 Biz Assurance - Designed by Curtiex Ventures.

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