Integrating LDAP into Mutt

If Mutt is your favorite email client and you ever wondered how to integrate email address from LDAP, this post shows you how to do this.

Setup

Install lbdb and libnet-ldap-perl:

aptitude install lbdb libnet-ldap-perl

Once you’ve done that, copy the lbdb configuration files into your home directory:

mkdir .lbdb
cp /etc/lbdb.rc .lbdb/rc
cp /etc/lbdb_ldap.rc .lbdb/ldap.rc

Add your LDAP server to the .lbdb/ldap.rc, e.g.:

%ldap_server_db = (
  'christianschenk' => ['localhost',
            'cn=users,dc=christianschenk,dc=org',
            'givenname sn cn mail', 'givenname cn sn mail o',
            '${mail}', '${givenname} ${sn}', '${o}' ]
);

Then add m_ldap to the line saying METHODS in .lbdb/rc and enable your LDAP server by adding it to the LDAP_NICKS like so:

LDAP_NICKS="christianschenk"

You can test your setup with the lbdbq command: simply call it with a string you’re searching for. Once it works for you like expected, add this line to your .muttrc:

set query_command="lbdbq '%s'"

Mutt will use this to send queries to lbdb.

Usage

If Mutt asks you for the email address simply enter some string and hit CTRL+t or TAB: this will auto-complete the address for you. That’s it.

5 thoughts on “Integrating LDAP into Mutt”

  1. So I have now this setup. Thanks!

    Say, I haven’t yet any addresses added so far.

    How can I start to use LDAP with this setup to add addresses?

    Regards, from Pál

  2. Hi Pál,
    simply use something like phpLdapAdmin or ldapvi to add addresses below the subtree that you want to store the addresses in. If you tell mutt to look for addresses in this subtree everything should be working just fine.

  3. Hi Schenk,

    I finally use LAM ( the LDAP Account Manager) to add addresses into my LDAP server (localhost). I have now some addresses bellow the subtree:
    dc=nodomain/
    dc=nodomain/
    ou=People

    Now, when I run:
    lbdbq Farkas

    I get the mesage:

    Search failed. LDAP server returned an error : 32, description: No such object at /usr/lib/lbdb/mutt_ldap_query line 198, line 558.
    lbdbq: no matches

    Farkas is the last name for my friend.

    I just edited the ldap.rc file:
    %ldap_server_db = (
    ‘cspldap’ => [‘localhost’, ‘ou=People,dc=nodomain,dc=nodomain’,
    ‘cn=admin,dc=nodomain,dc=nodomain’,
    ‘givenname sn cn mail’, ‘givenname cn sn mail o’,
    ‘${mail}’, ‘${givenname} ${sn}’, ‘${o}’ ]
    );

    Now when I run
    lbdbq Farkas

    I get:
    lbdbq: no matches

    So I think I don’t know what to change abowe to get match?
    I’m sure that I must to change the lines:
    ‘givenname sn cn mail’, ‘givenname cn sn mail o’,
    ‘${mail}’, ‘${givenname} ${sn}’, ‘${o}’ ]
    right?

    What am I doing wrong?

    Regards, from Pál

  4. Hi Pál,
    I must admit that it’s hard to tell why this isn’t working on your end because I don’t know exactly how you setup your directory. But I guess that you have to make sure that the LDAP search base is correct. Right after the search base you added 'cn=admin,dc=nodomain,dc=nodomain' and I’m not quite sure whether this is correct. Try removing that, maybe that helps.
    If all this doesn’t seem to work try using a simple call to ldap_search and try searching for your friend’s name manually. This way you can easily debug what’s going on and use the right parameters later when configuring the ldap_server_db variable in ldap.rc.

Comments are closed.