Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

Auto email all Active directory users

$
0
0

Hi,

Ive been trying to automate an email to 5 DL lists in my company. Ive tried stringing the lists together and all sorts but nothing seems to work until i came up with this solution:

$fromaddress = "ITHelpDesk.UK@companyname.co.uk"
$toaddressA = "_UK WSM1 All Users <maillist1@companyname.co.uk>"
$toaddressB = "_UK BAR1 All Users <maillist2@companyname.co.uk>"

$toaddressC=("DL Yate, Machine Systems  <maillist3@companyname.co.uk>")
$toaddressD=("DL Abercarn, Packaging UK <maillist4@companyname.com>")
$toaddressE=("DL Yate, Packaging UK <maillist5@companyname.co.uk>")

$bccaddress = "myemailaddress@companyname.co.uk"
$CCaddress =
$Subject = "UK IT Helpdesk"
$body = Get-Content C:\script\output.txt
$attachment = "C:\script\IT Helpdesk UK (UK).msg"
$smtpserver = "MYSMTPSERVER.COM"
 
####################################
 
$message = new-object System.Net.Mail.MailMessage
$message.From = $fromaddress
$message.Bcc.Add($bccaddress)
$message.To.Add($toaddressA)
$message.To.Add($toaddressB)
$message.To.Add($toaddressC)
$message.To.Add($toaddressD)
$message.To.Add($toaddressE)
$message.CC.Add($CCaddress)
$message.Bcc.Add($bccaddress)
$message.IsBodyHtml = $True
$message.Subject = $Subject
$attach = new-object Net.Mail.Attachment($attachment)
$message.Attachments.Add($attach)
$message.body = $body
$smtp = new-object Net.Mail.SmtpClient($smtpserver)
$smtp.Send($message)

#################################################

The problem is it sends me my bcc email and shows the first two email addresses but no one gets anything except me, also the last 3 addresses fail all together.

So, back to the drawing board, i decided id try and get the email addresses for each user in AD and email them seperatly, kind of like when their password is about to expire, but i couldnt get my head around it, and i feel dizzy now...

Can anyone help me with this? im really stuck.

Cheers

Res


Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>