Solved

Sending email to Multiple parties

Posted on 2013-05-16
5
334 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Why would I want to create a function for tracking messages? I am glad you asked. As with most monotonous/routine tasks, human error tends to creep in after doing the same task over and over again. By creating a function, you load the function once…
Set OWA language and time zone in Exchange for individuals, all users or per database.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

758 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now