#!/usr/bin/env python """ Test script to verify email sending via simulator API """ import os import sys import django # Setup Django os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings.dev') django.setup() from apps.notifications.services import NotificationService print("=" * 70) print("Testing Email Sending via Simulator API") print("=" * 70) # Test 1: Send plain text email print("\n1. Testing plain text email...") try: log = NotificationService.send_email( email='test@example.com', subject='Test Email - Plain Text', message='This is a test email sent via simulator API.' ) if log and log.status == 'sent': print(f"✅ Plain text email sent successfully!") print(f" Log ID: {log.id}") print(f" Recipient: {log.recipient}") else: print(f"❌ Failed to send plain text email") print(f" Status: {log.status if log else 'No log created'}") except Exception as e: print(f"❌ Error: {str(e)}") # Test 2: Send HTML email print("\n2. Testing HTML email...") try: html_message = """
This is a test email with HTML formatting.
It should display nicely in the simulator.
""" log = NotificationService.send_email( email='test@example.com', subject='Test Email - HTML', message='Plain text version of HTML email', html_message=html_message ) if log and log.status == 'sent': print(f"✅ HTML email sent successfully!") print(f" Log ID: {log.id}") print(f" Recipient: {log.recipient}") else: print(f"❌ Failed to send HTML email") print(f" Status: {log.status if log else 'No log created'}") except Exception as e: print(f"❌ Error: {str(e)}") # Test 3: Test SMS sending print("\n3. Testing SMS sending...") try: log = NotificationService.send_sms( phone='+966501234567', message='This is a test SMS sent via simulator API.' ) if log and log.status == 'sent': print(f"✅ SMS sent successfully!") print(f" Log ID: {log.id}") print(f" Recipient: {log.recipient}") else: print(f"❌ Failed to send SMS") print(f" Status: {log.status if log else 'No log created'}") except Exception as e: print(f"❌ Error: {str(e)}") print("\n" + "=" * 70) print("Test Complete!") print("=" * 70) print("\nCheck your terminal where the server is running to see formatted output.") print("Check logs/px360.log for detailed logs.")