From f82fd0db7b52dbaa36038f12684d443a45232a8b Mon Sep 17 00:00:00 2001 From: Jorran de Wit <jorrandewit@outlook.com> Date: Tue, 27 Mar 2018 20:35:02 +0200 Subject: [PATCH] Fix multiple mails in management cmd --- mails/management/commands/send_mails.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/mails/management/commands/send_mails.py b/mails/management/commands/send_mails.py index 651b92f5d..c684889d1 100644 --- a/mails/management/commands/send_mails.py +++ b/mails/management/commands/send_mails.py @@ -26,6 +26,7 @@ class Command(BaseCommand): raise AssertionError('The `EMAIL_BACKEND_ORIGINAL` cannot be the ModelEmailBackend') connection = get_connection(backend=backend, fail_silently=False) + count = 0 for db_mail in mails: mail = EmailMultiAlternatives( db_mail.subject, @@ -37,15 +38,17 @@ class Command(BaseCommand): connection=connection) if db_mail.body_html: mail.attach_alternative(db_mail.body_html, 'text/html') - response = mail.send() - if response: - db_mail.processed = True - db_mail.save() - return response + response = mail.send() + if response: + count += 1 + db_mail.processed = True + db_mail.save() + return count def handle(self, *args, **options): if options.get('id'): mails = MailLog.objects.filter(id=options['id']) else: mails = MailLog.objects.unprocessed() - self.send_mails(mails) + nr_mails = self.send_mails(mails) + self.stdout.write('Sent {} mails.'.format(nr_mails)) -- GitLab