from django.core.management.base import BaseCommand, CommandError from django.core.mail import send_mail class Command(BaseCommand): help = "Send a test email to verify SMTP configuration" def add_arguments(self, parser): parser.add_argument("to", help="Recipient email address") def handle(self, *args, **options): to = options["to"] try: send_mail( subject="PX360 Test Email", message="This is a test email from PX360. If you received this, your Outlook SMTP configuration is working correctly.", from_email=None, recipient_list=[to], fail_silently=False, ) except Exception as e: raise CommandError(f"Failed to send email: {e}") self.stdout.write(self.style.SUCCESS(f"Test email sent to {to}"))