reading sendmail alaises

A Meowbot meowbot at
Fri Feb 1 00:29:28 CET 2002

David Bear <iddwb at> wrote:

> I would like a quick way to resolve sendmail aliases.  I've thought
> about reading and parsing /etc/aliases myself but thats too much
> work.  Is there some module/interface to sendmail that would allow
> something like
> realaddress = sendmail.resolve-alias(name)
> Even though I could build a dictionary from aliases, the file may
> actually be in db format -- so I'm looking for a 'sendmail' way of
> grabbing them.

The anydbm module will let you access aliases.db in dictionary form.
The keys and values in aliaases.db are null terminated, so you'll need
to account for that.

>>> import anydbm
>>> aliases ="/etc/mail/aliases.db")
>>> aliases["nobody\0"]

You would still have to find and parse to learn the
location of aliases and aliases.db...

Or, if that's still too fiddly for you, you could spawn out to the
praliases program.

More information about the Python-list mailing list