- 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>
118 lines
No EOL
4 KiB
Python
118 lines
No EOL
4 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Interactive Email Test
|
|
Allows you to test with different Mailgun credentials
|
|
"""
|
|
|
|
import smtplib
|
|
from email.mime.multipart import MIMEMultipart
|
|
from email.mime.text import MIMEText
|
|
from datetime import datetime
|
|
import getpass
|
|
|
|
def test_email_with_credentials():
|
|
"""Interactive email test with user-provided credentials"""
|
|
|
|
print("JSON Workflow Processor - Interactive Email Test")
|
|
print("=" * 50)
|
|
|
|
# Get credentials from user
|
|
smtp_server = input("SMTP Server [smtp.mailgun.org]: ").strip() or "smtp.mailgun.org"
|
|
smtp_port = input("SMTP Port [587]: ").strip() or "587"
|
|
smtp_port = int(smtp_port)
|
|
|
|
sender_email = input("Sender Email [TWIST-UK-SERVER@oliver.agency]: ").strip() or "TWIST-UK-SERVER@oliver.agency"
|
|
smtp_user = input("SMTP Username: ").strip()
|
|
smtp_password = getpass.getpass("SMTP Password: ")
|
|
|
|
recipient = input("Test Recipient [daveporter@oliver.agency]: ").strip() or "daveporter@oliver.agency"
|
|
|
|
print("\nTesting with:")
|
|
print(f"Server: {smtp_server}:{smtp_port}")
|
|
print(f"User: {smtp_user}")
|
|
print(f"From: {sender_email}")
|
|
print(f"To: {recipient}")
|
|
print("-" * 50)
|
|
|
|
try:
|
|
# Create test message
|
|
msg = MIMEMultipart()
|
|
msg['From'] = sender_email
|
|
msg['To'] = recipient
|
|
msg['Subject'] = "JSON Workflow Processor - Email Test (Interactive)"
|
|
|
|
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: {recipient}
|
|
|
|
If you receive this email, the Mailgun configuration is working correctly!
|
|
|
|
You can now update the credentials in the reporting script.
|
|
"""
|
|
|
|
msg.attach(MIMEText(body, 'plain'))
|
|
|
|
# Connect to SMTP server
|
|
print(f"Connecting to {smtp_server}:{smtp_port}...")
|
|
server = smtplib.SMTP(smtp_server, smtp_port)
|
|
|
|
# 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 {recipient}...")
|
|
server.sendmail(sender_email, recipient, msg.as_string())
|
|
|
|
# Close connection
|
|
server.quit()
|
|
|
|
print("✅ Email sent successfully!")
|
|
print(f"Check {recipient} for the test message.")
|
|
|
|
# Show configuration to copy
|
|
print("\n" + "=" * 50)
|
|
print("SUCCESS! Use these settings in your reporting script:")
|
|
print(f'SMTP_SERVER = "{smtp_server}"')
|
|
print(f'SMTP_PORT = {smtp_port}')
|
|
print(f'SMTP_USER = "{smtp_user}"')
|
|
print(f'SMTP_PASSWORD = "{smtp_password}"')
|
|
print(f'SENDER_EMAIL = "{sender_email}"')
|
|
|
|
return True
|
|
|
|
except smtplib.SMTPAuthenticationError as e:
|
|
print(f"❌ Authentication failed: {e}")
|
|
print("\nTroubleshooting:")
|
|
print("1. Check your Mailgun domain and API key")
|
|
print("2. Make sure the domain is verified in Mailgun")
|
|
print("3. Check if you need to use an app-specific password")
|
|
return False
|
|
|
|
except Exception as e:
|
|
print(f"❌ Email test failed: {e}")
|
|
return False
|
|
|
|
if __name__ == "__main__":
|
|
success = test_email_with_credentials()
|
|
|
|
if not success:
|
|
print("\n" + "=" * 50)
|
|
print("MAILGUN SETUP HELP:")
|
|
print("1. Log into your Mailgun dashboard")
|
|
print("2. Go to 'Domains' and select your domain")
|
|
print("3. Go to 'Domain Settings' > 'SMTP credentials'")
|
|
print("4. Create a new SMTP user or use existing one")
|
|
print("5. Use those credentials in this test")
|
|
print("\nAlternatively, check if you need to:")
|
|
print("- Use port 587 instead of 25")
|
|
print("- Use your actual Mailgun API key")
|
|
print("- Verify your sending domain") |