diff --git a/src/fellchensammlung/templates/fellchensammlung/instance-health-check.html b/src/fellchensammlung/templates/fellchensammlung/instance-health-check.html index 5ea853f..5be5e85 100644 --- a/src/fellchensammlung/templates/fellchensammlung/instance-health-check.html +++ b/src/fellchensammlung/templates/fellchensammlung/instance-health-check.html @@ -119,4 +119,23 @@ +
+

{% translate 'Testemail versenden' %}

+
+ {% csrf_token %} + +
+

+ {% trans 'E-Mail Addresse an die die Test E-Mail gesendet werden soll' as target_email %} + + +

+

+ +

+
+
+
{% endblock content %} diff --git a/src/fellchensammlung/templates/fellchensammlung/mail/base.html b/src/fellchensammlung/templates/fellchensammlung/mail/base.html new file mode 100644 index 0000000..2ccfe46 --- /dev/null +++ b/src/fellchensammlung/templates/fellchensammlung/mail/base.html @@ -0,0 +1,76 @@ + + + + + + {% block title %}{% endblock %} + + + +
+ +{% block header %} + {% include "fellchensammlung/mail/header.html" %} +{% endblock %} +
+ {% block content %}{% endblock %} +
+{% include "fellchensammlung/mail/footer.html" %} +
+ + diff --git a/src/fellchensammlung/templates/fellchensammlung/mail/footer.html b/src/fellchensammlung/templates/fellchensammlung/mail/footer.html new file mode 100644 index 0000000..bc66ea0 --- /dev/null +++ b/src/fellchensammlung/templates/fellchensammlung/mail/footer.html @@ -0,0 +1,3 @@ + \ No newline at end of file diff --git a/src/fellchensammlung/templates/fellchensammlung/mail/header.html b/src/fellchensammlung/templates/fellchensammlung/mail/header.html new file mode 100644 index 0000000..672d3b7 --- /dev/null +++ b/src/fellchensammlung/templates/fellchensammlung/mail/header.html @@ -0,0 +1,3 @@ +
+ notfellchen.org +
\ No newline at end of file diff --git a/src/fellchensammlung/templates/fellchensammlung/mail/test.html b/src/fellchensammlung/templates/fellchensammlung/mail/test.html new file mode 100644 index 0000000..0452afd --- /dev/null +++ b/src/fellchensammlung/templates/fellchensammlung/mail/test.html @@ -0,0 +1,18 @@ +{% extends "fellchensammlung/mail/base.html" %} +{% load i18n %} +{% block title %} + {% translate 'Test-E-Mail' %} +{% endblock %} + +{% block content %} +

Moin,

+

+ das ist eine Test-E-Mail. +

+

+ Hier ist ein total wichtiger Button. Klick den mal! +

+

+ {% translate 'Zur Website' %} +

+{% endblock %} \ No newline at end of file diff --git a/src/fellchensammlung/tools/admin.py b/src/fellchensammlung/tools/admin.py index ed05460..7f37cef 100644 --- a/src/fellchensammlung/tools/admin.py +++ b/src/fellchensammlung/tools/admin.py @@ -1,10 +1,13 @@ import logging +from notfellchen import settings from django.utils import timezone from datetime import timedelta from django_super_deduper.merge import MergedModelInstance from django.template.loader import render_to_string +from django.core import mail +from django.utils.html import strip_tags from fellchensammlung.models import AdoptionNotice, Location, RescueOrganization, AdoptionNoticeStatus, Log, \ AdoptionNoticeNotification @@ -125,3 +128,13 @@ def export_orgs_as_vcf(): with open(filename, "w") as f: f.write(result) print(f"Wrote {len(rescue_orgs)} contacts to {filename}") + + +def send_test_email(email): + subject = 'Test E-Mail' + html_message = render_to_string('fellchensammlung/mail/test.html', {'context': 'values'}) + plain_message = strip_tags(html_message) + from_email = f'From <{settings.DEFAULT_FROM_EMAIL}>' + to = email + + mail.send_mail(subject, plain_message, from_email, [to], html_message=html_message) diff --git a/src/fellchensammlung/views.py b/src/fellchensammlung/views.py index eb582f8..49f2721 100644 --- a/src/fellchensammlung/views.py +++ b/src/fellchensammlung/views.py @@ -30,7 +30,7 @@ from .tools import i18n from .tools.geo import GeoAPI, zoom_level_for_radius from .tools.metrics import gather_metrics_data from .tools.admin import clean_locations, get_unchecked_adoption_notices, deactivate_unchecked_adoption_notices, \ - deactivate_404_adoption_notices + deactivate_404_adoption_notices, send_test_email from .tasks import post_adoption_notice_save from rest_framework.authtoken.models import Token @@ -638,6 +638,9 @@ def instance_health_check(request): deactivate_unchecked_adoption_notices() elif action == "deactivate_404": deactivate_404_adoption_notices() + elif action == "send_test_email": + target_email = request.POST.get("test_email_address") + send_test_email(target_email) number_of_adoption_notices = AdoptionNotice.objects.all().count() none_geocoded_adoption_notices = AdoptionNotice.objects.filter(location__isnull=True)