emelnik
asked on
Need a Powershell VBScript solution to send email to all members of a DL including nested DL's for Exchange 2010
Hi,
I need an automated script to send emails (regularly) to members of a DL. If the DL has a nested DL inside, it also has to send email to those members as well.
The solution could include Powershell script and/or VBScript.
The script(s) and procedure(s) will be executed by someone periodically.
Thank you
I need an automated script to send emails (regularly) to members of a DL. If the DL has a nested DL inside, it also has to send email to those members as well.
The solution could include Powershell script and/or VBScript.
The script(s) and procedure(s) will be executed by someone periodically.
Thank you
As it is a DL why are you not just emailing to the DL??
ASKER
Yes, need the script to mail to a particular DL and make sure all members get it. The issue here is that the scripts I found don't work for nested DL's.
Ideally when you send mail to a DL email address, the exchange server will expand the Dl's including nested Dl's and send the message to all recipients.. Are you saying it’s not working for you? Or Are you saying, you don’t want to send email to the distribution group email address?
ASKER
Let me share with you the script I have so far. This script was created to send test emails between two Exchange users. From what you are saying, this should also work with DL's and nested DL's?
Const ADS_PROPERTY_CLEAR = 1
Const ForReading = 1
Set objFSO = CreateObject("Scripting.Fi leSystemOb ject")
Set objTextFile = objFSO.OpenTextFile _
("C:\TOOLS\OrchE2K7-Policy Test\Emea\ ht-servers .txt", ForReading)
Const cdoSendUsingPickup = 1
Const cdoSendUsingPort = 2 'Must use this to use Delivery Notification
Const cdoAnonymous = 0
Const cdoNTLM = 2 'None
'Delivery Status Notifications
Const cdoDSNDefault = 0 'None
Const cdoDSNNever = 1 'None
Const cdoDSNFailure = 2 'Failure
Const cdoDSNSuccess = 4 'Success
Const cdoDSNDelay = 8 'Delay
Const cdoDSNSuccessFailOrDelay = 14 'Success, failure or delay
Const UserAddressDL1 = "ldnctisvcorres@contoso.co m"
Const UserAddressDL2 = "ldnctisvcorres@contoso.co m"
set objMsg = CreateObject("CDO.Message" )
set objConf = CreateObject("CDO.Configur ation")
Do Until objTextFile.AtEndOfStream
strComputer = objTextFile.ReadLine
Wscript.Echo strComputer
Set objFlds = objConf.Fields
With objFlds
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = cdoSendUsingPort
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = strComputer
.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = cdoNTLM
.Update
End With
strBody = "This email was sent via E2K7 hub " & strComputer & vbCRLF
'strBody = strBody & "THIS IS A TEST: PLEASE IGNORE. " & vbCRLF
strBody = strBody & vbCRLF
strBody = strBody & "This message should be blocked. If you received this message, then the Policy is broken." & vbCRLF
strBody = strBody & UserAddressDL1 + "Test users able to send restricted messages to " + UserAddressDL2 +" -Blocking" & vbCRLF
strBody = strBody & vbCRLF
strBody = strBody & "Please research issue" & vbCRLF
With objMsg
Set .Configuration = objConf
.To = UserAddressDL1
.From = UserAddressDL2
.Subject = "Active Policy Phase 3 Blocking:"
.TextBody = strBody
'use .HTMLBody to send HTML email."
.DSNOptions = cdoDSNSuccessFailOrDelay
.Fields.update
.Send
End With
Loop
objTextFile.Close
Const ADS_PROPERTY_CLEAR = 1
Const ForReading = 1
Set objFSO = CreateObject("Scripting.Fi
Set objTextFile = objFSO.OpenTextFile _
("C:\TOOLS\OrchE2K7-Policy
Const cdoSendUsingPickup = 1
Const cdoSendUsingPort = 2 'Must use this to use Delivery Notification
Const cdoAnonymous = 0
Const cdoNTLM = 2 'None
'Delivery Status Notifications
Const cdoDSNDefault = 0 'None
Const cdoDSNNever = 1 'None
Const cdoDSNFailure = 2 'Failure
Const cdoDSNSuccess = 4 'Success
Const cdoDSNDelay = 8 'Delay
Const cdoDSNSuccessFailOrDelay = 14 'Success, failure or delay
Const UserAddressDL1 = "ldnctisvcorres@contoso.co
Const UserAddressDL2 = "ldnctisvcorres@contoso.co
set objMsg = CreateObject("CDO.Message"
set objConf = CreateObject("CDO.Configur
Do Until objTextFile.AtEndOfStream
strComputer = objTextFile.ReadLine
Wscript.Echo strComputer
Set objFlds = objConf.Fields
With objFlds
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = cdoSendUsingPort
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = strComputer
.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = cdoNTLM
.Update
End With
strBody = "This email was sent via E2K7 hub " & strComputer & vbCRLF
'strBody = strBody & "THIS IS A TEST: PLEASE IGNORE. " & vbCRLF
strBody = strBody & vbCRLF
strBody = strBody & "This message should be blocked. If you received this message, then the Policy is broken." & vbCRLF
strBody = strBody & UserAddressDL1 + "Test users able to send restricted messages to " + UserAddressDL2 +" -Blocking" & vbCRLF
strBody = strBody & vbCRLF
strBody = strBody & "Please research issue" & vbCRLF
With objMsg
Set .Configuration = objConf
.To = UserAddressDL1
.From = UserAddressDL2
.Subject = "Active Policy Phase 3 Blocking:"
.TextBody = strBody
'use .HTMLBody to send HTML email."
.DSNOptions = cdoDSNSuccessFailOrDelay
.Fields.update
.Send
End With
Loop
objTextFile.Close
Yes.. If you send a mail to the group email address, then the mail will be delivered to all members in that group..
ASKER
OK, thanks. One final question, if I use the Send-MailMessage cmdlet in powershell to send email to Distribution Groups, then all members of the distribution group and nested distribution groups should get the message, correct?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Worked as the expert said.