test email notification and add local mail simualtion
This commit is contained in:
parent
6f06f8a3ed
commit
9b1fec9600
5 changed files with 305 additions and 13 deletions
|
@ -243,19 +243,23 @@ MEDIA_ROOT = BASE_DIR / "media"
|
|||
# Email
|
||||
# -----------------------------------
|
||||
|
||||
# Console Backend for Development Usage.
|
||||
# EMAIL_BACKEND = "django.core.mail.backends.console.EmailBackend"
|
||||
|
||||
# SMTP Backup for Production Usage.
|
||||
EMAIL_BACKEND = "django.core.mail.backends.smtp.EmailBackend"
|
||||
|
||||
if EMAIL_BACKEND == "django.core.mail.backends.smtp.EmailBackend":
|
||||
DEFAULT_FROM_EMAIL = env("DEFAULT_FROM_EMAIL")
|
||||
EMAIL_HOST_PASSWORD = env("EMAIL_HOST_PASSWORD")
|
||||
EMAIL_HOST_USER = env("EMAIL_HOST_USER")
|
||||
EMAIL_HOST = env("EMAIL_HOST")
|
||||
EMAIL_PORT = env("EMAIL_PORT")
|
||||
EMAIL_USE_TLS = True
|
||||
# Choose email backend based on DEBUG setting or environment variable
|
||||
if env.bool("DEBUG", default=True):
|
||||
# Development: Use console backend to display emails in terminal
|
||||
EMAIL_BACKEND = "django.core.mail.backends.console.EmailBackend"
|
||||
DEFAULT_FROM_EMAIL = "wildvogelhilfe@nabu-jena.de"
|
||||
print("📧 Development Email Backend: E-Mails werden in der Konsole angezeigt")
|
||||
else:
|
||||
# Production: Use SMTP backend for real email sending
|
||||
EMAIL_BACKEND = "django.core.mail.backends.smtp.EmailBackend"
|
||||
if EMAIL_BACKEND == "django.core.mail.backends.smtp.EmailBackend":
|
||||
DEFAULT_FROM_EMAIL = env("DEFAULT_FROM_EMAIL")
|
||||
EMAIL_HOST_PASSWORD = env("EMAIL_HOST_PASSWORD")
|
||||
EMAIL_HOST_USER = env("EMAIL_HOST_USER")
|
||||
EMAIL_HOST = env("EMAIL_HOST")
|
||||
EMAIL_PORT = env("EMAIL_PORT")
|
||||
EMAIL_USE_TLS = True
|
||||
print("📧 Production Email Backend: SMTP wird verwendet")
|
||||
|
||||
# -----------------------------------
|
||||
# Additional App Settings
|
||||
|
|
0
app/sendemail/management/__init__.py
Normal file
0
app/sendemail/management/__init__.py
Normal file
0
app/sendemail/management/commands/__init__.py
Normal file
0
app/sendemail/management/commands/__init__.py
Normal file
134
app/sendemail/management/commands/test_email_notifications.py
Normal file
134
app/sendemail/management/commands/test_email_notifications.py
Normal file
|
@ -0,0 +1,134 @@
|
|||
from django.core.management.base import BaseCommand
|
||||
from sendemail.models import Emailadress
|
||||
from bird.models import Bird, FallenBird
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = 'Test the email notification system configuration'
|
||||
|
||||
def handle(self, *args, **options):
|
||||
self.stdout.write("=" * 60)
|
||||
self.stdout.write("DJANGO FBF - E-MAIL BENACHRICHTIGUNGSTEST")
|
||||
self.stdout.write("=" * 60)
|
||||
self.stdout.write("")
|
||||
|
||||
# 1. Check existing email addresses
|
||||
self.stdout.write("1. VORHANDENE E-MAIL-ADRESSEN:")
|
||||
self.stdout.write("-" * 40)
|
||||
email_addresses = Emailadress.objects.all()
|
||||
|
||||
if not email_addresses.exists():
|
||||
self.stdout.write("❌ KEINE E-Mail-Adressen im System gefunden!")
|
||||
self.stdout.write(" Sie müssen zuerst E-Mail-Adressen über das Admin-Interface anlegen.")
|
||||
self.stdout.write("")
|
||||
else:
|
||||
for email in email_addresses:
|
||||
self.stdout.write(f"📧 {email.email_address}")
|
||||
self.stdout.write(f" 👤 Benutzer: {email.user.username}")
|
||||
self.stdout.write(f" 🏛️ Naturschutzbehörde: {'✅' if email.is_naturschutzbehoerde else '❌'}")
|
||||
self.stdout.write(f" 🏹 Jagdbehörde: {'✅' if email.is_jagdbehoerde else '❌'}")
|
||||
self.stdout.write(f" 🦅 Wildvogelhilfe-Team: {'✅' if email.is_wildvogelhilfe_team else '❌'}")
|
||||
self.stdout.write("")
|
||||
|
||||
# 2. Check bird species notification settings
|
||||
self.stdout.write("2. VOGELARTEN UND BENACHRICHTIGUNGSEINSTELLUNGEN:")
|
||||
self.stdout.write("-" * 40)
|
||||
birds = Bird.objects.all()
|
||||
|
||||
if not birds.exists():
|
||||
self.stdout.write("❌ KEINE Vogelarten im System gefunden!")
|
||||
self.stdout.write(" Sie müssen zuerst Vogelarten über das Admin-Interface anlegen.")
|
||||
self.stdout.write("")
|
||||
else:
|
||||
for bird in birds:
|
||||
self.stdout.write(f"🐦 {bird.name}")
|
||||
self.stdout.write(f" 🏛️ Naturschutzbehörde: {'✅' if bird.melden_an_naturschutzbehoerde else '❌'}")
|
||||
self.stdout.write(f" 🏹 Jagdbehörde: {'✅' if bird.melden_an_jagdbehoerde else '❌'}")
|
||||
self.stdout.write(f" 🦅 Wildvogelhilfe-Team: {'✅' if bird.melden_an_wildvogelhilfe_team else '❌'}")
|
||||
self.stdout.write("")
|
||||
|
||||
# 3. Simulate email notification for each bird species
|
||||
self.stdout.write("3. SIMULATION: WER WÜRDE BENACHRICHTIGT WERDEN?")
|
||||
self.stdout.write("-" * 40)
|
||||
|
||||
if birds.exists() and email_addresses.exists():
|
||||
for bird in birds:
|
||||
self.stdout.write(f"🐦 Wenn ein {bird.name} gefunden wird:")
|
||||
|
||||
recipients = []
|
||||
|
||||
# Check Naturschutzbehörde
|
||||
if bird.melden_an_naturschutzbehoerde:
|
||||
naturschutz_emails = Emailadress.objects.filter(is_naturschutzbehoerde=True)
|
||||
if naturschutz_emails.exists():
|
||||
recipients.extend([f"🏛️ {e.email_address}" for e in naturschutz_emails])
|
||||
else:
|
||||
self.stdout.write(" ⚠️ Naturschutzbehörde aktiviert, aber keine passenden E-Mail-Adressen gefunden!")
|
||||
|
||||
# Check Jagdbehörde
|
||||
if bird.melden_an_jagdbehoerde:
|
||||
jagd_emails = Emailadress.objects.filter(is_jagdbehoerde=True)
|
||||
if jagd_emails.exists():
|
||||
recipients.extend([f"🏹 {e.email_address}" for e in jagd_emails])
|
||||
else:
|
||||
self.stdout.write(" ⚠️ Jagdbehörde aktiviert, aber keine passenden E-Mail-Adressen gefunden!")
|
||||
|
||||
# Check Wildvogelhilfe-Team
|
||||
if bird.melden_an_wildvogelhilfe_team:
|
||||
team_emails = Emailadress.objects.filter(is_wildvogelhilfe_team=True)
|
||||
if team_emails.exists():
|
||||
recipients.extend([f"🦅 {e.email_address}" for e in team_emails])
|
||||
else:
|
||||
self.stdout.write(" ⚠️ Wildvogelhilfe-Team aktiviert, aber keine passenden E-Mail-Adressen gefunden!")
|
||||
|
||||
if recipients:
|
||||
self.stdout.write(" 📤 E-Mails würden gesendet an:")
|
||||
for recipient in recipients:
|
||||
self.stdout.write(f" {recipient}")
|
||||
else:
|
||||
self.stdout.write(" ❌ KEINE E-Mails würden gesendet!")
|
||||
self.stdout.write("")
|
||||
|
||||
# 4. Provide setup instructions
|
||||
self.stdout.write("4. SETUP-ANWEISUNGEN:")
|
||||
self.stdout.write("-" * 40)
|
||||
self.stdout.write("Für die Einrichtung des E-Mail-Systems:")
|
||||
self.stdout.write("")
|
||||
self.stdout.write("A) E-Mail-Adressen hinzufügen:")
|
||||
self.stdout.write(" 1. Gehen Sie zum Admin-Interface: http://localhost:8008/admin/")
|
||||
self.stdout.write(" 2. Melden Sie sich mit admin/abcdef an")
|
||||
self.stdout.write(" 3. Wählen Sie 'Mail Empfänger' > 'Emailadressen' > 'Hinzufügen'")
|
||||
self.stdout.write(" 4. Geben Sie die E-Mail-Adresse ein")
|
||||
self.stdout.write(" 5. Wählen Sie die entsprechenden Kategorien:")
|
||||
self.stdout.write(" - Naturschutzbehörde: für offizielle Meldungen")
|
||||
self.stdout.write(" - Jagdbehörde: für jagdbare Arten")
|
||||
self.stdout.write(" - Wildvogelhilfe-Team: für interne Benachrichtigungen")
|
||||
self.stdout.write("")
|
||||
self.stdout.write("B) Vogelarten-Benachrichtigungen konfigurieren:")
|
||||
self.stdout.write(" 1. Gehen Sie zu 'Vögel' > 'Birds' > [Vogelart auswählen]")
|
||||
self.stdout.write(" 2. Aktivieren Sie die gewünschten Benachrichtigungen:")
|
||||
self.stdout.write(" - 'Melden an Naturschutzbehörde'")
|
||||
self.stdout.write(" - 'Melden an Jagdbehörde'")
|
||||
self.stdout.write(" - 'Melden an Wildvogelhilfe-Team'")
|
||||
self.stdout.write("")
|
||||
self.stdout.write("C) Testen:")
|
||||
self.stdout.write(" 1. Erstellen Sie einen neuen Patienten über 'http://localhost:8008/'")
|
||||
self.stdout.write(" 2. Wählen Sie eine Vogelart aus")
|
||||
self.stdout.write(" 3. Das System sendet automatisch E-Mails basierend auf den Einstellungen")
|
||||
self.stdout.write("")
|
||||
|
||||
# 5. Summary
|
||||
self.stdout.write("5. ZUSAMMENFASSUNG:")
|
||||
self.stdout.write("-" * 40)
|
||||
self.stdout.write(f"📧 E-Mail-Adressen im System: {email_addresses.count()}")
|
||||
self.stdout.write(f"🐦 Vogelarten im System: {birds.count()}")
|
||||
|
||||
if email_addresses.exists() and birds.exists():
|
||||
self.stdout.write("✅ System ist grundsätzlich funktionsfähig")
|
||||
else:
|
||||
self.stdout.write("❌ System benötigt weitere Konfiguration")
|
||||
|
||||
self.stdout.write("")
|
||||
self.stdout.write("=" * 60)
|
||||
self.stdout.write("Test abgeschlossen! Öffnen Sie http://localhost:8008/admin/ für weitere Konfiguration.")
|
||||
self.stdout.write("=" * 60)
|
154
test_email_notifications.py
Normal file
154
test_email_notifications.py
Normal file
|
@ -0,0 +1,154 @@
|
|||
#!/usr/bin/env python3
|
||||
"""
|
||||
Test script for Django FBF Email Notification System
|
||||
|
||||
This script helps you test which email addresses would receive notifications
|
||||
when a new patient (fallen bird) is created in the system.
|
||||
"""
|
||||
|
||||
import os
|
||||
import sys
|
||||
import django
|
||||
|
||||
# Add the Django project path
|
||||
sys.path.append('/Users/maximilianfischer/git/django_fbf/app')
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'core.settings')
|
||||
|
||||
# Setup Django
|
||||
django.setup()
|
||||
|
||||
from sendemail.models import Emailadress
|
||||
from bird.models import Bird, FallenBird
|
||||
from django.contrib.auth.models import User
|
||||
|
||||
def test_email_notification_system():
|
||||
"""Test the email notification system configuration."""
|
||||
|
||||
print("=" * 60)
|
||||
print("DJANGO FBF - E-MAIL BENACHRICHTIGUNGSTEST")
|
||||
print("=" * 60)
|
||||
print()
|
||||
|
||||
# 1. Check existing email addresses
|
||||
print("1. VORHANDENE E-MAIL-ADRESSEN:")
|
||||
print("-" * 40)
|
||||
email_addresses = Emailadress.objects.all()
|
||||
|
||||
if not email_addresses.exists():
|
||||
print("❌ KEINE E-Mail-Adressen im System gefunden!")
|
||||
print(" Sie müssen zuerst E-Mail-Adressen über das Admin-Interface anlegen.")
|
||||
print()
|
||||
else:
|
||||
for email in email_addresses:
|
||||
print(f"📧 {email.email_address}")
|
||||
print(f" 👤 Benutzer: {email.user.username}")
|
||||
print(f" 🏛️ Naturschutzbehörde: {'✅' if email.is_naturschutzbehoerde else '❌'}")
|
||||
print(f" 🏹 Jagdbehörde: {'✅' if email.is_jagdbehoerde else '❌'}")
|
||||
print(f" 🦅 Wildvogelhilfe-Team: {'✅' if email.is_wildvogelhilfe_team else '❌'}")
|
||||
print()
|
||||
|
||||
# 2. Check bird species notification settings
|
||||
print("2. VOGELARTEN UND BENACHRICHTIGUNGSEINSTELLUNGEN:")
|
||||
print("-" * 40)
|
||||
birds = Bird.objects.all()
|
||||
|
||||
if not birds.exists():
|
||||
print("❌ KEINE Vogelarten im System gefunden!")
|
||||
print(" Sie müssen zuerst Vogelarten über das Admin-Interface anlegen.")
|
||||
print()
|
||||
else:
|
||||
for bird in birds:
|
||||
print(f"🐦 {bird.name}")
|
||||
print(f" 🏛️ Naturschutzbehörde: {'✅' if bird.melden_an_naturschutzbehoerde else '❌'}")
|
||||
print(f" 🏹 Jagdbehörde: {'✅' if bird.melden_an_jagdbehoerde else '❌'}")
|
||||
print(f" 🦅 Wildvogelhilfe-Team: {'✅' if bird.melden_an_wildvogelhilfe_team else '❌'}")
|
||||
print()
|
||||
|
||||
# 3. Simulate email notification for each bird species
|
||||
print("3. SIMULATION: WER WÜRDE BENACHRICHTIGT WERDEN?")
|
||||
print("-" * 40)
|
||||
|
||||
if birds.exists() and email_addresses.exists():
|
||||
for bird in birds:
|
||||
print(f"🐦 Wenn ein {bird.name} gefunden wird:")
|
||||
|
||||
recipients = []
|
||||
|
||||
# Check Naturschutzbehörde
|
||||
if bird.melden_an_naturschutzbehoerde:
|
||||
naturschutz_emails = Emailadress.objects.filter(is_naturschutzbehoerde=True)
|
||||
if naturschutz_emails.exists():
|
||||
recipients.extend([f"🏛️ {e.email_address}" for e in naturschutz_emails])
|
||||
else:
|
||||
print(" ⚠️ Naturschutzbehörde aktiviert, aber keine passenden E-Mail-Adressen gefunden!")
|
||||
|
||||
# Check Jagdbehörde
|
||||
if bird.melden_an_jagdbehoerde:
|
||||
jagd_emails = Emailadress.objects.filter(is_jagdbehoerde=True)
|
||||
if jagd_emails.exists():
|
||||
recipients.extend([f"🏹 {e.email_address}" for e in jagd_emails])
|
||||
else:
|
||||
print(" ⚠️ Jagdbehörde aktiviert, aber keine passenden E-Mail-Adressen gefunden!")
|
||||
|
||||
# Check Wildvogelhilfe-Team
|
||||
if bird.melden_an_wildvogelhilfe_team:
|
||||
team_emails = Emailadress.objects.filter(is_wildvogelhilfe_team=True)
|
||||
if team_emails.exists():
|
||||
recipients.extend([f"🦅 {e.email_address}" for e in team_emails])
|
||||
else:
|
||||
print(" ⚠️ Wildvogelhilfe-Team aktiviert, aber keine passenden E-Mail-Adressen gefunden!")
|
||||
|
||||
if recipients:
|
||||
print(" 📤 E-Mails würden gesendet an:")
|
||||
for recipient in recipients:
|
||||
print(f" {recipient}")
|
||||
else:
|
||||
print(" ❌ KEINE E-Mails würden gesendet!")
|
||||
print()
|
||||
|
||||
# 4. Provide setup instructions
|
||||
print("4. SETUP-ANWEISUNGEN:")
|
||||
print("-" * 40)
|
||||
print("Für die Einrichtung des E-Mail-Systems:")
|
||||
print()
|
||||
print("A) E-Mail-Adressen hinzufügen:")
|
||||
print(" 1. Gehen Sie zum Admin-Interface: http://localhost:8008/admin/")
|
||||
print(" 2. Melden Sie sich mit admin/abcdef an")
|
||||
print(" 3. Wählen Sie 'Mail Empfänger' > 'Emailadressen' > 'Hinzufügen'")
|
||||
print(" 4. Geben Sie die E-Mail-Adresse ein")
|
||||
print(" 5. Wählen Sie die entsprechenden Kategorien:")
|
||||
print(" - Naturschutzbehörde: für offizielle Meldungen")
|
||||
print(" - Jagdbehörde: für jagdbare Arten")
|
||||
print(" - Wildvogelhilfe-Team: für interne Benachrichtigungen")
|
||||
print()
|
||||
print("B) Vogelarten-Benachrichtigungen konfigurieren:")
|
||||
print(" 1. Gehen Sie zu 'Vögel' > 'Birds' > [Vogelart auswählen]")
|
||||
print(" 2. Aktivieren Sie die gewünschten Benachrichtigungen:")
|
||||
print(" - 'Melden an Naturschutzbehörde'")
|
||||
print(" - 'Melden an Jagdbehörde'")
|
||||
print(" - 'Melden an Wildvogelhilfe-Team'")
|
||||
print()
|
||||
print("C) Testen:")
|
||||
print(" 1. Erstellen Sie einen neuen Patienten über 'http://localhost:8008/'")
|
||||
print(" 2. Wählen Sie eine Vogelart aus")
|
||||
print(" 3. Das System sendet automatisch E-Mails basierend auf den Einstellungen")
|
||||
print()
|
||||
|
||||
# 5. Summary
|
||||
print("5. ZUSAMMENFASSUNG:")
|
||||
print("-" * 40)
|
||||
print(f"📧 E-Mail-Adressen im System: {email_addresses.count()}")
|
||||
print(f"🐦 Vogelarten im System: {birds.count()}")
|
||||
|
||||
if email_addresses.exists() and birds.exists():
|
||||
print("✅ System ist grundsätzlich funktionsfähig")
|
||||
else:
|
||||
print("❌ System benötigt weitere Konfiguration")
|
||||
|
||||
print()
|
||||
print("=" * 60)
|
||||
print("Test abgeschlossen! Öffnen Sie http://localhost:8008/admin/ für weitere Konfiguration.")
|
||||
print("=" * 60)
|
||||
|
||||
if __name__ == "__main__":
|
||||
test_email_notification_system()
|
Loading…
Add table
Add a link
Reference in a new issue