Improved connection clean-up for SMTP backend.

This commit is contained in:
Carlton Gibson 2023-03-14 11:10:06 +01:00 committed by GitHub
parent de0c7744be
commit 8a844e761d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 6 deletions

View File

@ -130,10 +130,12 @@ class EmailBackend(BaseEmailBackend):
# Trying to send would be pointless. # Trying to send would be pointless.
return 0 return 0
num_sent = 0 num_sent = 0
try:
for message in email_messages: for message in email_messages:
sent = self._send(message) sent = self._send(message)
if sent: if sent:
num_sent += 1 num_sent += 1
finally:
if new_conn_created: if new_conn_created:
self.close() self.close()
return num_sent return num_sent