1

Topic: Get list of all users/emails, for every domain

Is it possible to run a quick scripts which gets a list of all the email addresses for every domain?

I want to send out a mass email using bcc letting all the users know of any changes, so ideally this list would be separated by comma.

==== Required information ====
- iRedMail version: 0.8.3 LDAP
====

----

Spider Email Archiver: On-Premises, lightweight email archiving software developed by iRedMail team. Supports Amazon S3 compatible storage and custom branding.

2

Re: Get list of all users/emails, for every domain

You can get all mail users/lists with command "ldapsearch". smile

3

Re: Get list of all users/emails, for every domain

Thank you but I dont have any knowledge of working with ldap so the "ldapsearch" hasn't helped.

I was able to simplify one of your examples so this 90% achieves what I need.

Although I find this is also listing the domain names.

#!/usr/bin/env python
# encoding: utf-8

import sys
import ldap

# Note:
#   * bind_dn must have write privilege on LDAP server.
uri = 'ldap://127.0.0.1:389'
basedn = 'o=domains,dc=example,dc=com'
bind_dn = 'cn=Manager,dc=example,dc=com'
bind_pw = 'pass'

# Initialize LDAP connection.
conn = ldap.initialize(uri=uri, trace_level=0,)
conn.bind_s(bind_dn, bind_pw)

# Get all mail users.
allUsers = conn.search_s(
        basedn,
        ldap.SCOPE_SUBTREE,
        "(objectClass=mailUser)",
        ['mail'],
        )

# Print all email users separated by comma
for user in allUsers:
    (dn, entry) = user
    mail = entry['mail'][0]
    
    if len(mail) > 0:    
        print >> sys.stdout, "%s, " %(mail)

# Unbind connection.
conn.unbind()