Skip to content

How to quickly get a list of all users and their emails in Django using django-extensions

Consider the case where you need the emails of all your customers. You might be doing this to set up a mailing list for your newsletter or as part of a marketing campaign.

Here is the simplest way I’ve found.

Firstly install the absolutely magnificent django-extensions app.

pip install django-extensions

Then enable it in your Django project:

INSTALLED_APPS = (
    ...
    'django_extensions',
    ...
)

Django-extensions is a eclectic mix of functions that offer some really good functionality. Many of the functions in there you won’t use – but don’t feel guilty! Use what you need.

To get the list of users emails run this command:

python manage.py export_emails > addresses.txt

This puts a list of emails into a text file call addresses.txt in the same directory as your manage.py (in most cases).

There are other formats you can use, such as creating a google csv file:

python manage.py export_emails --format=google > google.csv

There are the django-extensions docs too!

It is well worth reviewing the docs of django-extensions – who knows there might be other functions in there you might use!

Leave a Reply