Commit 4a4ed9ee authored by Sébastiaan Versteeg's avatar Sébastiaan Versteeg Committed by Luko van der Maas

Add mailinglists for newsletter receivers and refactor mailinglists services

parent 0adf268d
......@@ -266,7 +266,7 @@ class GSuiteSyncService:
moderated=automatic_list['moderated'],
name=automatic_list['name'],
description=automatic_list['description'],
aliases=automatic_list['aliases'],
aliases=automatic_list.get('aliases', []),
addresses=automatic_list['addresses']
)
......
This diff is collapsed.
......@@ -52,7 +52,7 @@ class GSuiteSyncTestCase(TestCase):
def test_default_lists(self):
self.assertEqual(len(self.sync_service._get_default_lists()),
18)
14)
def test_automatic_to_group(self):
group = GSuiteSyncService._automatic_to_group({
......
......@@ -9,7 +9,6 @@ from django.template.loader import get_template
from django.utils import translation, timezone
from django.utils.timezone import make_aware
from members.models import Member
from newsletters import services
from partners.models import Partner
......@@ -42,11 +41,6 @@ def send_newsletter(newsletter):
for language in settings.LANGUAGES:
translation.activate(language[0])
members = Member.current_members.all().filter(
profile__receive_newsletter=True,
profile__language=language[0]
)
subject = '[THALIA] ' + newsletter.title
context = {
......@@ -65,24 +59,17 @@ def send_newsletter(newsletter):
msg = EmailMultiAlternatives(
subject=subject,
body=text_message,
to=[f'newsletter-{language[0]}@{settings.GSUITE_DOMAIN}'],
from_email=from_email,
connection=connection
)
msg.attach_alternative(html_message, "text/html")
for member in members:
if not member.email:
return
msg.to = [member.email]
try:
msg.send()
logger.info('Sent newsletter to %s (%s)',
member.get_full_name(),
member.email)
except SMTPException as e:
logger.error('Failed to send the newsletter to %s (%s)',
member.get_full_name(),
member.email, e)
try:
msg.send()
logger.info(f'Sent {language[1]} newsletter')
except SMTPException as e:
logger.error(f'Failed to send the {language[1]} '
f'newsletter: {e}')
translation.deactivate()
......@@ -120,7 +120,7 @@ class NewslettersTest(TestCase):
self.client.post(reverse(
'newsletters:admin-send',
args=[testletter.pk]), {'post': 'yes'})
self.assertEqual(len(mail.outbox), 3)
self.assertEqual(len(mail.outbox), 2)
def test_email_html_and_text(self):
testletter = Newsletter.objects.create(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment