Windows Vista Forums
Vista Forums Home Join Vista Forums Donate Vista Tutorials Tags

Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > PowerShell

Sending Mail from powershell

Update your Vista Drivers Update Your Drivers Now!!
Closed Thread
 
Thread Tools Display Modes
Old 05-13-2008   #1 (permalink)
Arman Obosyan
Guest


 

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]
Guest


 

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
Guest


 

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
Closed Thread

Thread Tools
Display Modes



Similar Threads
Thread Thread Starter Forum Replies Last Post
SENDING E-MAIL FROM WINDOWS MAIL CONTACT ADDRESS BOOK pedidocsbp Vista mail 3 05-14-2008 03:25 AM
Re: Suffering from sending mail from Windows Mail?? Your prayers a River Ron Vista mail 1 04-01-2008 10:48 PM
Error sending E-mail with Windows Vista and Windoes Mail grburris Vista mail 8 03-14-2008 04:54 PM
slow performance creating and sending e-mail with windows mail Dlawyers Vista mail 5 08-05-2007 03:31 AM
Fixed Windows Mail Outbox Stuck Message & E-mail Not Sending Trick Vista mail 11 03-17-2007 01:30 PM


Update your Vista Drivers Update Your Vista Drivers Now!!

Vistax64.com 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 2005-2008