Adgetsmtp

From My Notepad
Jump to: navigation, search

To use this script, save it as adgetsmtp.vbs and update the Set Container line with your Active Directory domain.

After the script is run, two files are created in the current working directory: smtpaddresses.txt and smtpaddresses-mysql.txt.  The first can be copied directly into a Postfix relay-recipients file.  The second are insert statements for MailZu.

You can download the script from here.

'Global variables
Dim Container
Dim fileSmtpAddresses
Dim fileSmtpAddressesMysql
Dim FileSystem

'Initialize global variables
Set FileSystem = WScript.CreateObject("Scripting.FileSystemObject")
Set fileSmtpAddresses = FileSystem.CreateTextFile("smtpaddresses.txt", True)
Set fileSmtpAddressesMysql = FileSystem.CreateTextFile("smtpaddresses-mysql.txt", True)

'Replace with valid DN of the container you want to enumerate
Set Container=GetObject("LDAP://DC=domain,DC=loc")

'Enumerate Container
EnumerateUsers Container

'Clean up
fileSmtpAddresses.Close
fileSmtpAddressesMysql.Close

Set FileSystem = Nothing
Set Container = Nothing

'Say Finished when your done
WScript.Echo "Finished"
WScript.Quit(0)

'List all Users
Sub EnumerateUsers(Cont)
Dim User

'Go through all Users and select them
For Each User In Cont
Select Case LCase(User.Class)

'If you find Users
Case "user"
  'Select all proxyAddresses
  Dim Alias
  If Not IsEmpty(User.proxyAddresses) Then
    For Each Alias in User.proxyAddresses
  	If InStr(1,Alias,"smtp",1) > 0 Then
			fileSmtpAddresses.WriteLine Replace(Alias,"smtp:","",1,1,1) & " OK"
			fileSmtpAddressesMysql.WriteLine "insert into mzusers (email) values ('" & Replace(Alias,"smtp:","",1,1,1) & "');"
		End If
    'WScript.Echo Alias
  	Next
  End If

Case "organizationalunit" , "container"
  EnumerateUsers User

End Select
Next
End Sub