Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sending an email to every group member

Status
Not open for further replies.

acl03

MIS
Jun 13, 2005
1,077
US
I was looking for a way to send an email to every member in a security gtoup (maybe even with recursion for nested groups?)

Does anyone know if this is difficult, or if maybe it exists already?



Thanks,
Andrew
 
Mail enable the group and let Windows manage it for you.

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
We don't use exchange, we have Lotus Notes - is that still possible?



Thanks,
Andrew
 
Yikes, don't know. Have not used Notes in over 10 years. If it integrates with AD then I would think it should work.

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
How difficult is it to use VBS to write a script that would pull group members and just send a mail via an SNMP server?



Thanks,
Andrew
 
Don't you mean SMTP?

Same unknown applies here. It does not take much to enumerate group members. the question is do your members all have the mail field or proxyAddresses field in AD populated to be able to get the address from that user object? Or is notes maintaining its own list?

Listing the members of the group can be done like this:

Code:
On Error Resume Next
 
Set objGroup = GetObject _
  ("LDAP://cn=Scientists,ou=R&D,dc=NA,dc=fabrikam,dc=com")
objGroup.GetInfo
 
arrMemberOf = objGroup.GetEx("member")
 
WScript.Echo "Members:"
For Each strMember in arrMemberOf
    WScript.echo strMember
Next

From within the For Each you would then need to bind to the user object and get the mail ID. You will need to do a little digging with ADSIEdit and verify if your AD has the needed information. If you cna confirm that I can assist with the rest of the code you need.

Once you have a list of the mail IDs, then it is a simple matter to use CDO to send out the mail via SMTP.

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
Actually, I did think ahead when I built this AD to fill in the email address of every user. Only issue is that i'd need to do a modification of the email address if we're going to use our SMTP server(yes, I meant SMTP, thanks).

For example:

Joe User has email address of juser@company.com.

If we want to send him mail via our company SMTP server internally, we need to send it to juser@internal.company.com.

I'm sure that modification could easily be done with a regex or something of the sort. I guess getting the email address field and the actual sending of the email would be what I'd want assistance with. Thanks again.





Thanks,
Andrew
 
Code:
[green]
'==========================================================='
' NAME: SendMailTogroupMembers.vbs
'
' AUTHOR: Mark D. MacLachlan , The Spider's Parlor
' URL: [URL unfurl="true"]http://www.thespidersparlor.com[/URL]
' DATE  : 12/24/2007
' COPYRIGHT (c) 2007 All Rights Reserved
'
' COMMENT: 
'
'    THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
'    ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
'    THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
'    PARTICULAR PURPOSE.
'
'    IN NO EVENT SHALL THE SPIDER'S PARLOR AND/OR ITS RESPECTIVE SUPPLIERS 
'    BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
'    DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
'    WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
'    ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
'    OF THIS CODE OR INFORMATION.
'
'===========================================================
On Error Resume Next
Dim strFrom, strMyIP, strTo 
Dim priorityFlag, strSubject, strBody, objUser, objGroup

[red]
'***********************************************************
'***********************************************************
'Begin Modification section[/red][green]
' Set the company specific information['green]
strFrom = "mark@thespidersparlor.com"[green]
' Set the SMTP server IP[/green]
strMyIP = "192.168.0.13" [green]
' Set the subject text[/green]
strSubject = "Important Message to Group X"[green]
' Set the body text[/green]
strBody = "Due to bedgetary constraints, you will only be paid 50% salary for any days worked that end in a Y"[green]
' Set the priority to high importance.  Change to any other value for normal priority"[/green]
priorityFlag = "Yes"[green]
' Specify the group object LDAP Path [/green]
Set objGroup = GetObject _
  ("LDAP://cn=Scientists,ou=R&D,dc=NA,dc=fabrikam,dc=com")[red]
' End modification section
'***********************************************************
'***********************************************************
[/red]

  
objGroup.GetInfo
 
arrMemberOf = objGroup.GetEx("member")
 
For Each strMember in arrMemberOf
	Set objUser = GetObject("LDAP://" & strMember)
	strEmail = Replace(objUser.mail,"@","@internal.")
    emailList = emailList & strEmail & ";"
Next

strTo = emailList

[green]
' Set the visual basic constants as they do not exist within VBScript.
' Do not set your smtp server information here.[/green]
Const cdoSendUsingMethod = "[URL unfurl="true"]http://schemas.microsoft.com/cdo/configuration/sendusing",[/URL] _
cdoSendUsingPort = 2, _
cdoSMTPServer = "[URL unfurl="true"]http://schemas.microsoft.com/cdo/configuration/smtpserver"[/URL]
[green]
' Create the CDO connections.[/green]
Dim iMsg, iConf, Flds
Set iMsg = CreateObject("CDO.Message")
Set iConf = CreateObject("CDO.Configuration")
Set Flds = iConf.Fields
[green]
' SMTP server configuration.[/green]
With Flds
.Item(cdoSendUsingMethod) = cdoSendUsingPort
[green]
' Set the SMTP server address here.[/green]
.Item(cdoSMTPServer) = strMyIP
.Update
End With
[green]
' Set the message properties.[/green]
With iMsg
Set .Configuration = iConf
.To = strTo
.From = strFrom
.Subject = strSubject
.TextBody = strBody
End With
[green]
'Send high priority[/green]
If priorityflag = "Yes" Then 
	iMsg.Fields.Item("urn:schemas:mailheader:X-MSMail-Priority") = "High" ' For Outlook 2003
	iMsg.Fields.Item("urn:schemas:mailheader:X-Priority") = 2 ' For Outlook 2003 also
	iMsg.Fields.Item("urn:schemas:httpmail:importance") = 2 ' For Outlook Express
	iMsg.Fields.Update
End If
[green]
'Send the message.[/green]
iMsg.Send 
MsgBox "Done"

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
Wow - thanks Mark. Gonna play around with it now, I'll let you know how it work.



Thanks,
Andrew
 
Ok, modified it to point to a group in our AD. i know it's pulling group members properly (i did a msgbox with strEmail in it in the for loop).

What is that line that points out to an http:// site? Is that actually trying to go out to the internet? If so, that wouldn't work due to us having a proxy server.

No errors come back, but the email never gets delivered...



Thanks,
Andrew
 
Add Microsoft.com to the allowed list on your Proxy Server so it can get through.

That line is needed for the CDO to work.

Your only other option would be to try and script the notes client to send out the mail, but I have no idea if that is even possible. If you used Outlook it would be easy.

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
Well, unfortunately I have no access to our proxy server. What information is it going out to the internet to get? Seems odd that it'd have to go out to an http site just send a message using an internal server.



Thanks,
Andrew
 
How to use CDO:
thread705-1369407

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
This code works fine....is VBScript sending the message on its own? I guess it doesn't need an SMTP server?


Code:
Set objMessage = CreateObject("CDO.Message")
objMessage.Subject = "Test Subject"
objMessage.From = "me@company.com"
objMessage.To = "juser1@company.com"
objMessage.TextBody = "This is some sample message text."
objMessage.Send



Thanks,
Andrew
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top