json-parser-twist-metaserver/OLD/test_email.py
Dave Porter af8acbd986 Add all project files including previous versions and documentation
- Added INSTALL_GUIDE.md and README.md documentation
- Added OLD/ folder with previous script versions for reference
- Added data/ folder with sample JSON test files
- Added older json_workflow_processor-hybrid-protected.py version
- Excludes venv and .DS_Store (per .gitignore)

Complete project backup with full history and test data.

Co-Authored-By: Claude Sonnet 4.5 (1M context) <noreply@anthropic.com>
2026-02-06 11:07:22 -05:00

103 lines
No EOL
3.2 KiB
Python

#!/usr/bin/env python3
"""
Test Email Functionality
Test the Mailgun SMTP connection and credentials
"""
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from datetime import datetime
# Mailgun settings with correct SMTP password
SMTP_SERVER = "smtp.mailgun.org"
SMTP_PORT = 587
SMTP_USER = "twist@mail.dev.oliver.solutions"
SMTP_PASSWORD = "102115e9f3b9d7332d0cd1d4329bc0d4-77751bfc-ca066b71"
SENDER_EMAIL = "TWIST-UK-SERVER@oliver.agency"
TEST_EMAIL = "daveporter@oliver.agency"
def test_email_connection():
"""Test the email connection and send a test message"""
try:
print("Testing Mailgun SMTP connection...")
# Create test message
msg = MIMEMultipart()
msg['From'] = SENDER_EMAIL
msg['To'] = TEST_EMAIL
msg['Subject'] = "JSON Workflow Processor - Email Test"
body = f"""This is a test email from the JSON Workflow Processor.
Test Details:
- Time: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}
- SMTP Server: {SMTP_SERVER}:{SMTP_PORT}
- From: {SENDER_EMAIL}
- To: {TEST_EMAIL}
If you receive this email, the Mailgun configuration is working correctly!
The daily workflow reports will be sent to this email address at midnight each day.
"""
msg.attach(MIMEText(body, 'plain'))
# Connect to SMTP server
print(f"Connecting to {SMTP_SERVER}:{SMTP_PORT}...")
server = smtplib.SMTP(SMTP_SERVER, SMTP_PORT)
# Enable debug output
server.set_debuglevel(1)
# Start TLS encryption
print("Starting TLS...")
server.starttls()
# Login with credentials
print(f"Logging in as {SMTP_USER}...")
server.login(SMTP_USER, SMTP_PASSWORD)
# Send email
print(f"Sending test email to {TEST_EMAIL}...")
server.sendmail(SENDER_EMAIL, TEST_EMAIL, msg.as_string())
# Close connection
server.quit()
print("✅ Email sent successfully!")
print(f"Check {TEST_EMAIL} for the test message.")
return True
except smtplib.SMTPAuthenticationError as e:
print(f"❌ Authentication failed: {e}")
print("The username/password may be incorrect.")
return False
except smtplib.SMTPRecipientsRefused as e:
print(f"❌ Recipient refused: {e}")
print("The recipient email may be invalid.")
return False
except smtplib.SMTPServerDisconnected as e:
print(f"❌ Server disconnected: {e}")
print("Connection to SMTP server was lost.")
return False
except Exception as e:
print(f"❌ Email test failed: {e}")
print("There may be a network issue or configuration problem.")
return False
if __name__ == "__main__":
print("JSON Workflow Processor - Email Test")
print("=" * 50)
success = test_email_connection()
print("=" * 50)
if success:
print("✅ Email configuration is working correctly!")
print("Daily reports will be sent successfully.")
else:
print("❌ Email configuration needs to be fixed.")
print("Please check the credentials and try again.")