Solved

Sending email to Multiple parties

Posted on 2013-05-16
5
337 Views
Last Modified: 2013-05-17
Hi Powershell Experts,

I use the following code without problem

send-MailMessage -SmtpServer $smtp -To "user1@xxx.com.sg", "user2@xxx.com.sg" -From $from -Subject $subject -Body $body -BodyAsHtml

But using variable fails???
$to = "user1@xxx.com.sg", "user2@xxx.com.sg"
send-MailMessage -SmtpServer $smtp -To $to  -From $from -Subject $subject -Body $body -BodyAsHtml

Can help explain where I go wrong?
0
Comment
Question by:NicksonKoh
  • 2
  • 2
5 Comments
 
LVL 42

Expert Comment

by:sedgwick
ID: 39173892
that should work:
$recipients = "user1@xxx.com.sg", "user2@xxx.com.sg" 
send-MailMessage -SmtpServer $smtp -To $recipients -From $from -Subject $subject -Body $body -BodyAsHtml

Open in new window

0
 
LVL 17

Author Comment

by:NicksonKoh
ID: 39173933
Hi sedgwick,

I just tested again and while there is no error, it is still not working correctly as the email is only sent to the first person in $recipients. So for the above case, I receive an email with just

To : user1@xxx.com.sg

user2 does not appear in the To list.
0
 
LVL 44

Accepted Solution

by:
Rainer Jeschor earned 500 total points
ID: 39173951
Hi,
can you try this:
$to = @("user1@xxx.com.sg", "user2@xxx.com.sg")
0
 
LVL 17

Author Closing Comment

by:NicksonKoh
ID: 39173974
Thx it worked! Does the @() means parameters?
0
 
LVL 44

Expert Comment

by:Rainer Jeschor
ID: 39173977
Nope, it means an array of strings (or objects)
0

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
This article will help you understand what HashTables are and how to use them in PowerShell.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question