![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | 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 Specs![]() |
| | #2 (permalink) |
| | 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 ? 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 Specs![]() |
| | #3 (permalink) |
| | 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 Specs![]() |
![]() |
| 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 | |||