Powershell

PowerShell Syntax for Send-Mailmessage – Email to Multiple Recipients

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 = "[email protected]"
$EmailTo = "[email protected]", "[email protected]", "[email protected]"
$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.

About the author

Muhammad Farhan

I am a Computer Science graduate and now a technical writer who loves to provide the easiest solutions to the most difficult problems related to Windows, Linux, and Web designing. My love for Computer Science emerges every day because of its ease in our everyday life.