2

This function trigger an error that doesn't make sense to me:

File "/venv/virtualenvs/ZHR-f7z/oscar/apps/communication/utils.py", line 128, in send_email_messages
email.send()

in the settings:

EMAIL_USE_SSL = None #False doesn't change result
EMAIL_USE_TLS = None

Someting wrong is happening as both are None so these can't be True:

File "/venv/virtualenvs/ZHR-f7z/lib/python3.9/site-packages/django/core/mail/backends/smtp.py", line 31, in __init__
        self.use_ssl = settings.EMAIL_USE_SSL if use_ssl is None else use_ssl
        self.timeout = settings.EMAIL_TIMEOUT if timeout is None else timeout
        self.ssl_keyfile = settings.EMAIL_SSL_KEYFILE if ssl_keyfile is None else ssl_keyfile
        self.ssl_certfile = settings.EMAIL_SSL_CERTFILE if ssl_certfile is None else ssl_certfile
        if self.use_ssl and self.use_tls:
            raise ValueError(
                "EMAIL_USE_TLS/EMAIL_USE_SSL are mutually exclusive, so only set "
                "one of those settings to True.")
        self.connection = None
        self._lock = threading.RLock()



[console ready]
>>> use_ssl
>>> self.use_ssl
'None'
>>> self.use_tls
'None'
>>> 

If I start a shell with:

>>> from django.core import mail
>>> mail.send_mail(
...             'Subject here', 'Here is the message.',
...             'mailfrom', ['mailto'],
...             fail_silently=False,
...         )

result in a success.

Any advice as the settings are both false and the ValueError should be trigger if both are True?

Thanks, BR

user2239318
  • 2,578
  • 7
  • 28
  • 50

2 Answers2

2

EMAIL_USE_TLS and EMAIL_USE_SSL are mutually exclusive You should choose which secure connection to use, depending on you email provider.

In Django EMAIL_USE_TLS uses port 587 by default, where and EMAIL_USE_SSL uses port 465 instead

So, correct setting must be

EMAIL_USE_SSL = False
EMAIL_USE_TLS = True

or

EMAIL_USE_SSL = True
EMAIL_USE_TLS = False

see Django Doc on settings EMAIL_USE_TLS/EMAIL_USE_SSL

manuel_b
  • 1,646
  • 3
  • 20
  • 29
  • thanks for the answer I've tried with TLS enabled but still ends in the same ValueError: [console ready] >>> self.use_ssl 'True' >>> self.use_tls 'False' ValueError: EMAIL_USE_TLS/EMAIL_USE_SSL are mutually exclusive, so only set one of those settings to True. – user2239318 Jan 31 '22 at 10:34
1

enter image description here

I'mg a little confused, the TLS is True and the SSL is False, condition to trigger the ValueErrror means:

if self.use_ssl==True and self.use_tls == True 

I would expect that both as True are needed to trigger the Exception. But here is triggered while only one is True.

Or I'm missing something else?

user2239318
  • 2,578
  • 7
  • 28
  • 50
  • I am encountering the same issue - has anyone figured out why we see this error and how to correct it? thanks. – stevec Nov 01 '22 at 15:07