Search code examples
pythondjangoemaildjango-settingsdjango-email

Django mails not being saved (File backend)


I have configured Django to use a file backend for email sending on my local machine. This seemed to work fine earlier on, and all mails were recorded in the directory I had specified in my settings.py file:

EMAIL_BACKEND = 'django.core.mail.backends.filebased.EmailBackend'
EMAIL_FILE_PATH = '/code/mails/'

However, this suddenly stopped working. I have checked the permissions of the folder, and this seems to be fine. There is no error that I can see. I'm using docker, and when I start the Python server I have the logs shown in my terminal. Normally when there is an error I see it there. But nothing appears. To test things, I have renamed the folder and tried sending a mail. This time, no error appears either. In production, where my settings.py are different but all else is the same, the emails are sent out just fine. So the code seems to be working, but the local filebased backend seems to be a problem.

Anybody any idea?

I have configured these log settings:

LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'handlers': {
        'file': {
            'level': 'DEBUG',
            'class': 'logging.FileHandler',
            'filename': '/code/logs/debug.log',
        },
    },
    'loggers': {
        'django': {
            'handlers': ['file'],
            'level': 'DEBUG',
            'propagate': True,
        },
    },
}

The logs seem to work fine and provide detailed logging; but none of it related to the e-mail error.


Solution

  • As you can see in the code there's a lot of raises: https://github.com/django/django/blob/stable/2.1.x/django/core/mail/backends/filebased.py#L13

    So if with your settings, and the correct permissions on your folder you cannot see email or errors maybe there's some settings that overwrite the two settings you posted here.

    Check again your local setting and be sure there's only one EMAIL_BACKEND declared.