133 lines
4.0 KiB
Python
133 lines
4.0 KiB
Python
#!/usr/bin/env python3
|
|
"""Quick email sending test script"""
|
|
|
|
import sys
|
|
from datetime import datetime
|
|
|
|
# Add src to path
|
|
sys.path.insert(0, "src")
|
|
|
|
from src.config import get_config
|
|
from src.logger import setup_logger
|
|
from src.email.sender import EmailSender
|
|
|
|
|
|
def test_email():
|
|
"""Send a test email"""
|
|
setup_logger()
|
|
config = get_config()
|
|
|
|
print("\n" + "=" * 60)
|
|
print("Testing Email Configuration")
|
|
print("=" * 60)
|
|
|
|
print(f"\nSMTP Server: {config.email.smtp.host}:{config.email.smtp.port}")
|
|
print(f"TLS: {config.email.smtp.use_tls}")
|
|
print(f"SSL: {config.email.smtp.use_ssl}")
|
|
print(f"From: {config.email.from_}")
|
|
print(f"To: {config.email.to}")
|
|
print(f"Username: {config.env.smtp_username or '(not set)'}")
|
|
print(f"Password: {'***' if config.env.smtp_password else '(not set)'}")
|
|
|
|
print("\nSending test email...")
|
|
|
|
# Create test email content
|
|
subject = "News Agent Test Email"
|
|
|
|
html_content = (
|
|
"""
|
|
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<style>
|
|
body { font-family: Arial, sans-serif; padding: 20px; }
|
|
.header { background-color: #2563eb; color: white; padding: 20px; border-radius: 8px; }
|
|
.content { margin-top: 20px; line-height: 1.6; }
|
|
.success { color: #16a34a; font-weight: bold; }
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="header">
|
|
<h1>✓ News Agent Email Test</h1>
|
|
</div>
|
|
<div class="content">
|
|
<p class="success">Congratulations! Your email configuration is working correctly.</p>
|
|
|
|
<p><strong>Test Details:</strong></p>
|
|
<ul>
|
|
<li>Date: """
|
|
+ datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
|
+ """</li>
|
|
<li>SMTP Server: """
|
|
+ f"{config.email.smtp.host}:{config.email.smtp.port}"
|
|
+ """</li>
|
|
<li>Encryption: """
|
|
+ ("TLS" if config.email.smtp.use_tls else "SSL" if config.email.smtp.use_ssl else "None")
|
|
+ """</li>
|
|
</ul>
|
|
|
|
<p>Your News Agent is now ready to send daily digests!</p>
|
|
|
|
<hr>
|
|
<p style="color: #6b7280; font-size: 12px;">
|
|
This is a test email from News Agent. If you received this,
|
|
your SMTP configuration is correct and you should start receiving
|
|
daily news digests.
|
|
</p>
|
|
</div>
|
|
</body>
|
|
</html>
|
|
"""
|
|
)
|
|
|
|
text_content = f"""
|
|
News Agent Email Test
|
|
=====================
|
|
|
|
✓ Congratulations! Your email configuration is working correctly.
|
|
|
|
Test Details:
|
|
- Date: {datetime.now().strftime("%Y-%m-%d %H:%M:%S")}
|
|
- SMTP Server: {config.email.smtp.host}:{config.email.smtp.port}
|
|
- Encryption: {"TLS" if config.email.smtp.use_tls else "SSL" if config.email.smtp.use_ssl else "None"}
|
|
|
|
Your News Agent is now ready to send daily digests!
|
|
|
|
---
|
|
This is a test email from News Agent. If you received this,
|
|
your SMTP configuration is correct and you should start receiving
|
|
daily news digests.
|
|
"""
|
|
|
|
# Send email
|
|
sender = EmailSender()
|
|
success = sender.send(subject, html_content, text_content)
|
|
|
|
print("\n" + "=" * 60)
|
|
if success:
|
|
print("✓ SUCCESS! Test email sent successfully!")
|
|
print(f"✓ Check your inbox: {config.email.to}")
|
|
else:
|
|
print("✗ FAILED! Email could not be sent.")
|
|
print("✗ Check the error messages above.")
|
|
print("\nTroubleshooting steps:")
|
|
print("1. Verify SMTP credentials in .env file")
|
|
print("2. Check SMTP server settings in config.yaml")
|
|
print("3. Review logs: cat data/logs/news-agent.log")
|
|
print("4. See SMTP_CONFIG.md for detailed troubleshooting")
|
|
print("=" * 60 + "\n")
|
|
|
|
return success
|
|
|
|
|
|
if __name__ == "__main__":
|
|
try:
|
|
success = test_email()
|
|
sys.exit(0 if success else 1)
|
|
except Exception as e:
|
|
print(f"\n✗ ERROR: {e}")
|
|
import traceback
|
|
|
|
traceback.print_exc()
|
|
sys.exit(1)
|