File size: 2,124 Bytes
6853143
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/env python3
"""
Test script for the email sending tool
"""

import os
from dotenv import load_dotenv
import resend

# Load environment variables
load_dotenv(dotenv_path=".env")

# Test configuration
TO_EMAIL = "charles.grandjean@pentx.ai"
SUBJECT = "Test Email from CyberLegalAI"
CONTENT = "This is a test email from the CyberLegalAI email sending tool."

def test_email():
    """Test sending an email using Resend"""
    print("📧 Testing Email Sending Tool")
    print("=" * 50)
    
    # Check environment variables
    api_key = os.getenv("RESEND_API_KEY")
    from_email = os.getenv("RESEND_FROM_EMAIL")
    from_name = os.getenv("RESEND_FROM_NAME", "CyberLegalAI")
    
    print(f"\n✅ Configuration:")
    print(f"   API Key: {'✓ Set' if api_key else '✗ Missing'}")
    print(f"   From Email: {from_email}")
    print(f"   From Name: {from_name}")
    
    if not api_key or not from_email:
        print("\n❌ Error: Missing required environment variables")
        print("   Please ensure RESEND_API_KEY and RESEND_FROM_EMAIL are set in .env")
        return False
    
    try:
        # Initialize Resend
        resend.api_key = api_key
        
        # Send test email
        print(f"\n📤 Sending test email to {TO_EMAIL}...")
        
        params = {
            "from": f"{from_name} <{from_email}>",
            "to": [TO_EMAIL],
            "subject": SUBJECT,
            "text": CONTENT
        }
        
        response = resend.Emails.send(params)
        
        print(f"\n✅ Email sent successfully!")
        print(f"   Email ID: {response.get('id', 'N/A')}")
        print(f"   From: {params['from']}")
        print(f"   To: {TO_EMAIL}")
        print(f"   Subject: {SUBJECT}")
        
        return True
        
    except Exception as e:
        print(f"\n❌ Failed to send email")
        print(f"   Error: {str(e)}")
        return False

if __name__ == "__main__":
    success = test_email()
    
    if success:
        print("\n🎉 Email tool is working correctly!")
    else:
        print("\n❌ Email tool test failed - please check configuration")