over 3 years ago

## Django SMTP AUTH extension not supported by server

I had a local postfix mail server setup and trying to send an email with the following setting:

Here is the code responsible for sending the email:

Because the mail server is setup locally, there is no need to supply any user name or password. So I didn't bother to specify them in the settings.py. When I had the server running, here is the error that I encountered:

The error message is very misleading, but this particular caught my eyes:

I didn't specify any username and password because I don't think I need them. Maybe I should put them back in? So I added the following lines:

Wholah, it worked! But why? So I looked under the hood:

When using the EmailBackend class, a username and password can be passed in as parameters. I didn't pass either of them in my view function. Thus, Django defaults them to settings.EMAIL_HOST_USER and settings.EMAIL_HOST_PASSWORD. However, EMAIL_HOST_USER and EMAIL_HOST_PASSWORD are not defined in the settings file. So by the time self.connection.login(self.username, self.password) is called, both username and password are None.

The error message SMTP AUTH extension not supported by server is generated by python's own smtp library. I guess Django can throw a more meaningful error before this to make this error more apparent.