email testing

This commit is contained in:
2026-01-26 12:55:56 +01:00
parent e64465a7e6
commit f8684077a2
7 changed files with 447 additions and 12 deletions

109
src/test_email_simple.py Normal file
View File

@@ -0,0 +1,109 @@
#!/usr/bin/env python3
"""Simple email test - run with: python -m src.test_email_simple"""
from datetime import datetime
from .config import get_config
from .logger import setup_logger
from .email.sender import EmailSender
def main():
"""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 = f"""
<!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: {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")
if __name__ == "__main__":
main()