Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - Sending Mail from powershell

Reply
 
Old 05-13-2008   #1 (permalink)
Arman Obosyan


 
 

Sending Mail from powershell

Hello,
I need to send mail to users from powershell,
I try to:

$SMTPserver = "hub01.corp.net"
$from = "admin@xxxxxx"
$to = "user01@xxxxxx"
$subject = "Inform You...."
$emailbody = "Service unavailable from 10pm to 11pm..."
$mailer = New-Object Net.Mail.SMTPclient($SMTPserver)
$msg = New-Object Net.Mail.MailMessage($from, $to, $subject, $emailbody)
$mailer.send($msg)


But how can I specify parameters and get data from CSV file for mass mailing
e.g.
$to = "user01@xxxxxx" ($_.usersfromcsvfile??? )
$emailbody = "Service unavailable from 10pm to 11pm..."
($_.mailbodyfromcsvfile??? )


What exactly I need to modify in this ps script to get data from Import-CSV
?


Thank you.

Arman.






My System SpecsSystem Spec
Old 05-13-2008   #2 (permalink)
Marco Shaw [MVP]


 
 

Re: Sending Mail from powershell

Arman Obosyan wrote:
Quote:

> Hello,
> I need to send mail to users from powershell,
> I try to:
>
> $SMTPserver = "hub01.corp.net"
> $from = "admin@xxxxxx"
> $to = "user01@xxxxxx"
> $subject = "Inform You...."
> $emailbody = "Service unavailable from 10pm to 11pm..."
> $mailer = New-Object Net.Mail.SMTPclient($SMTPserver)
> $msg = New-Object Net.Mail.MailMessage($from, $to, $subject, $emailbody)
> $mailer.send($msg)
>
>
> But how can I specify parameters and get data from CSV file for mass
> mailing
> e.g.
> $to = "user01@xxxxxx" ($_.usersfromcsvfile??? )
> $emailbody = "Service unavailable from 10pm to 11pm..."
> ($_.mailbodyfromcsvfile??? )
>
>
> What exactly I need to modify in this ps script to get data from
> Import-CSV ?
Here's an example:

PSH>gc test.csv
users
joe
foo
bar
PSH>import-csv test.csv|%{$emails+=$_.users+","}
PSH>$emails.trimend(",")
joe,foo,bar

So maybe the above and:
PSH>$trimmed=$emails.trimend(",")
PSH>$to = "user01@xxxxxx"+"$trimmed"

Marco

--
Microsoft MVP - Windows PowerShell
http://www.microsoft.com/mvp

PowerGadgets MVP
http://www.powergadgets.com/mvp

Blog:
http://marcoshaw.blogspot.com
My System SpecsSystem Spec
Old 05-15-2008   #3 (permalink)
Arman Obosyan


 
 

Re: Sending Mail from powershell

Nice,

Thank you!


Arman Obosyan.


"Marco Shaw [MVP]" <marco.shaw@_NO_SPAM_gmail.com> wrote in message
news:#Q3EHrRtIHA.1772@xxxxxx
Quote:

> Arman Obosyan wrote:
Quote:

>> Hello,
>> I need to send mail to users from powershell,
>> I try to:
>>
>> $SMTPserver = "hub01.corp.net"
>> $from = "admin@xxxxxx"
>> $to = "user01@xxxxxx"
>> $subject = "Inform You...."
>> $emailbody = "Service unavailable from 10pm to 11pm..."
>> $mailer = New-Object Net.Mail.SMTPclient($SMTPserver)
>> $msg = New-Object Net.Mail.MailMessage($from, $to, $subject, $emailbody)
>> $mailer.send($msg)
>>
>>
>> But how can I specify parameters and get data from CSV file for mass
>> mailing
>> e.g.
>> $to = "user01@xxxxxx" ($_.usersfromcsvfile??? )
>> $emailbody = "Service unavailable from 10pm to 11pm..."
>> ($_.mailbodyfromcsvfile??? )
>>
>>
>> What exactly I need to modify in this ps script to get data from
>> Import-CSV ?
>
> Here's an example:
>
> PSH>gc test.csv
> users
> joe
> foo
> bar
> PSH>import-csv test.csv|%{$emails+=$_.users+","}
> PSH>$emails.trimend(",")
> joe,foo,bar
>
> So maybe the above and:
> PSH>$trimmed=$emails.trimend(",")
> PSH>$to = "user01@xxxxxx"+"$trimmed"
>
> Marco
>
> --
> Microsoft MVP - Windows PowerShell
> http://www.microsoft.com/mvp
>
> PowerGadgets MVP
> http://www.powergadgets.com/mvp
>
> Blog:
> http://marcoshaw.blogspot.com
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Powershell - COM Port - Sending SMS PowerShell
Error sending e-mail from my premium Yahoo account with Live mail Live Mail
sending e-mail using right click or file-send-to e-mail recipient Vista mail
Error sending E-mail with Windows Vista and Windoes Mail Vista mail
Fixed Windows Mail Outbox Stuck Message & E-mail Not Sending Vista mail


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46