The Multifunctioning DBA

Oct 28 2008   11:06PM GMT

Powershell Email



Posted by: Colin Smith
Tags:
Microsoft Windows
Powershell

The other day I was out reading some blog posts and I ran across one that talked about needing to send an email to a ridiculous number of people. So many that they could not all be fit into the to and cc fields of Outlook. So I thought why not Powershell this. All you would need is a listing of the email addresses that you want to send the mail to and then a file that contains the body of the email. For the addresses I would hope that you have them in your contacts and then you can do an export to a file. Once you have that then type the body of the email into a file and now lets write a script to send it.


$users = get-content “path to file with listing of email addresses”

foreach ($user in $users)

{

$smtpServer = “name of smtp server to send mail”

$smtp = New-Object Net.Mail.SmtpClient($smtpServer)

$emailFrom = “yourname@yourdomain.com”

$subject = “Some Subject Line”

foreach ($line in Get-Content “Path to file with body of email”)

{

$body += “$line `n”

}

$smtp.Send($EmailFrom,$user,$subject,$body)

}

}

So there you go. No limit on how many users this script will send the mail to. Any questions or comments please let me know and also goto sysadminsmith.com to drop me an email.

 Comment on this Post

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when other members comment.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to: