- Email: process + send tools - Security: documentație securizare Clawdbot - KB: coaching, youtube notes (Monica Ion, ClawdBot 10x) - Reflecții: audit relații/bani, pattern 'nu merit', dizolvare vină - Insights: 2026-02-01 + backlog + content recomandat - Memory: heartbeat state, reguli comunicare
71 lines
2.1 KiB
Python
71 lines
2.1 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Simple SMTP email sender for echo@romfast.ro
|
|
Usage: python3 email_send.py "recipient@email.com" "Subject" "Body text"
|
|
"""
|
|
|
|
import smtplib
|
|
import ssl
|
|
import sys
|
|
import os
|
|
from email.mime.text import MIMEText
|
|
from email.mime.multipart import MIMEMultipart
|
|
from pathlib import Path
|
|
|
|
# Load .env file
|
|
env_path = Path(__file__).parent.parent / '.env'
|
|
if env_path.exists():
|
|
with open(env_path) as f:
|
|
for line in f:
|
|
line = line.strip()
|
|
if line and not line.startswith('#') and '=' in line:
|
|
key, value = line.split('=', 1)
|
|
os.environ.setdefault(key, value)
|
|
|
|
# SMTP Configuration from environment
|
|
SMTP_SERVER = os.environ.get('EMAIL_SERVER', 'mail.romfast.ro')
|
|
SMTP_PORT = 465
|
|
SMTP_USER = os.environ.get('EMAIL_USER', 'echo@romfast.ro')
|
|
SMTP_PASS = os.environ.get('EMAIL_PASSWORD', '')
|
|
FROM_NAME = "Echo 🌀"
|
|
|
|
def send_email(to_email: str, subject: str, body: str, html: bool = False) -> dict:
|
|
"""Send an email via SMTP SSL"""
|
|
try:
|
|
# Create message
|
|
msg = MIMEMultipart("alternative")
|
|
msg["Subject"] = subject
|
|
msg["From"] = f"{FROM_NAME} <{SMTP_USER}>"
|
|
msg["To"] = to_email
|
|
|
|
# Attach body
|
|
if html:
|
|
msg.attach(MIMEText(body, "html", "utf-8"))
|
|
else:
|
|
msg.attach(MIMEText(body, "plain", "utf-8"))
|
|
|
|
# Connect and send
|
|
context = ssl.create_default_context()
|
|
with smtplib.SMTP_SSL(SMTP_SERVER, SMTP_PORT, context=context) as server:
|
|
server.login(SMTP_USER, SMTP_PASS)
|
|
server.sendmail(SMTP_USER, to_email, msg.as_string())
|
|
|
|
return {"ok": True, "to": to_email, "subject": subject}
|
|
|
|
except Exception as e:
|
|
return {"ok": False, "error": str(e)}
|
|
|
|
if __name__ == "__main__":
|
|
if len(sys.argv) < 4:
|
|
print("Usage: python3 email_send.py <to> <subject> <body>")
|
|
sys.exit(1)
|
|
|
|
to = sys.argv[1]
|
|
subject = sys.argv[2]
|
|
body = sys.argv[3]
|
|
|
|
result = send_email(to, subject, body)
|
|
|
|
import json
|
|
print(json.dumps(result))
|