diff options
author | Giancarlo Razzolini <grazzolini@archlinux.org> | 2019-10-25 14:06:52 -0300 |
---|---|---|
committer | Giancarlo Razzolini <grazzolini@archlinux.org> | 2019-10-25 14:06:52 -0300 |
commit | 4120191306c31dac18817244cb91697638e2d738 (patch) | |
tree | e033da7a41cdc2ac197fbf34e4e05f6799cace17 | |
parent | c292bdd05d9205c3b1123a6c7f1a91dde7c0ebfd (diff) | |
download | archweb-4120191306c31dac18817244cb91697638e2d738.tar.gz archweb-4120191306c31dac18817244cb91697638e2d738.zip |
news: Change the news app to use the EmailMessage class to be able to include the mailman password
Due to spamming to arch-announce mail list, we now use a poster password to make sure only authorized
emails are allowed through to the list.
-rw-r--r-- | news/views.py | 18 | ||||
-rw-r--r-- | settings.py | 3 |
2 files changed, 14 insertions, 7 deletions
diff --git a/news/views.py b/news/views.py index 48295944..20a74c3c 100644 --- a/news/views.py +++ b/news/views.py @@ -1,5 +1,6 @@ from django import forms -from django.core.mail import send_mail +from django.conf import settings +from django.core.mail import EmailMessage from django.http import HttpResponse from django.shortcuts import get_object_or_404, redirect from django.template import loader @@ -39,16 +40,19 @@ class NewsCreateView(CreateView): newsitem.author = self.request.user newsitem.slug = find_unique_slug(News, newsitem.title) newsitem.save() - if newsitem.send_announce: + if newsitem.send_announce and settings.MAILMAN_PASSWORD: ctx = { 'news': newsitem, } + headers = { + 'Approved': settings.MAILMAN_PASSWORD, + } template = loader.get_template('news/news_email_notification.txt') - send_mail('[arch-announce] %s' % newsitem.title, - template.render(ctx), - '"Arch Linux: Recent news updates: %s" <arch-announce@archlinux.org>' % newsitem.author.get_full_name(), - ['arch-announce@archlinux.org'], - fail_silently=True) + EmailMessage(subject='[arch-announce] %s' % newsitem.title, + body=template.render(ctx), + from_email='"Arch Linux: Recent news updates: %s" <arch-announce@archlinux.org>' % newsitem.author.get_full_name(), + to=['arch-announce@archlinux.org'], + headers=headers).send() return super(NewsCreateView, self).form_valid(form) diff --git a/settings.py b/settings.py index e91b5aa6..3201f218 100644 --- a/settings.py +++ b/settings.py @@ -178,6 +178,9 @@ COUNTRIES_OVERRIDE = { # Make this unique, and don't share it with anybody. SECRET_KEY = '00000000000000000000000000000000000000000000000' +# Mailman poster password for announcements +MAILMAN_PASSWORD = '' + DATABASES = { 'default': { 'ENGINE': 'django.db.backends.sqlite3', |