diff --git a/birdsong/backends/smtp.py b/birdsong/backends/smtp.py index e7b8d5f..ccb92ad 100644 --- a/birdsong/backends/smtp.py +++ b/birdsong/backends/smtp.py @@ -43,7 +43,7 @@ class SendCampaignThread(Thread): class SMTPEmailBackend(BaseEmailBackend): - def send_campaign(self, request, campaign, contacts): + def send_campaign(self, request, campaign, contacts, test_send=False): messages = [] for contact in contacts: @@ -58,7 +58,10 @@ class SMTPEmailBackend(BaseEmailBackend): 'to': [contact.email], 'reply_to': [self.reply_to], }) - - campaign_thread = SendCampaignThread( - campaign.pk, [c.pk for c in contacts], messages) - campaign_thread.start() + if test_send: + # Don't mark as complete, don't worry about threading + send_mass_html_mail(messages) + else: + campaign_thread = SendCampaignThread( + campaign.pk, [c.pk for c in contacts], messages) + campaign_thread.start() diff --git a/birdsong/views/actions.py b/birdsong/views/actions.py index 592a0ff..a2544bd 100644 --- a/birdsong/views/actions.py +++ b/birdsong/views/actions.py @@ -16,13 +16,14 @@ def send_campaign(backend, request, campaign, contacts): campaign.status = CampaignStatus.SENDING campaign.save() backend.send_campaign(request, campaign, contacts) + messages.success(request, f"Campaign sent to {len(contacts)} contacts") return redirect_helper(campaign) def send_test(backend, request, campaign, test_contact): campaign.subject = f"[TEST] {campaign.subject}" - backend.send_campaign(request, campaign, [test_contact]) + backend.send_campaign(request, campaign, [test_contact], test_send=True) messages.success(request, "Test email sent, please check your inbox") return redirect_helper(campaign)