network_mode: host # Nutzt das Host-Netzwerk
This commit is contained in:
@@ -5,30 +5,38 @@ import base64
|
||||
import gzip
|
||||
import logging
|
||||
import os
|
||||
from dotenv import load_dotenv
|
||||
|
||||
# Python-Version prüfen
|
||||
if sys.version_info < (3, 12):
|
||||
raise RuntimeError("Python 3.12 oder höher erforderlich")
|
||||
|
||||
# .env-Datei laden
|
||||
load_dotenv()
|
||||
|
||||
app = Flask(__name__)
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
# Konfiguration
|
||||
# SMTP_HOST = "mailcowdockerized-postfix-mailcow-1" # MailCow Postfix-Container
|
||||
SMTP_HOST = "postfix-mailcow" # MailCow Postfix-Container
|
||||
SMTP_HOST = "localhost" # Verweist auf Host-Port 25
|
||||
SMTP_PORT = 25 # Fest auf Port 25 ohne TLS
|
||||
API_TOKEN = os.environ.get('API_TOKEN', 'your-api-token') # Muss mit Lambda übereinstimmen
|
||||
logger.info(f"API_TOKEN: {API_TOKEN}")
|
||||
API_TOKEN = os.environ.get('API_TOKEN')
|
||||
if not API_TOKEN:
|
||||
raise ValueError("API_TOKEN Umgebungsvariable nicht gesetzt")
|
||||
|
||||
logger.info(f"API_TOKEN loaded: {API_TOKEN}")
|
||||
|
||||
@app.route('/process/<domain>', methods=['POST'])
|
||||
def process_email(domain):
|
||||
# Authentifizierung via Bearer-Token
|
||||
auth_header = request.headers.get('Authorization')
|
||||
if not auth_header or auth_header != f'Bearer {API_TOKEN}':
|
||||
return jsonify({'error': 'Unauthorized'}), 401
|
||||
|
||||
data = request.get_json()
|
||||
if not data:
|
||||
return jsonify({'error': 'Invalid JSON payload'}), 400
|
||||
|
||||
request_id = data.get('request_id')
|
||||
email_content = data.get('email_content')
|
||||
compressed = data.get('compressed', False)
|
||||
@@ -36,14 +44,12 @@ def process_email(domain):
|
||||
logger.info(f"[{request_id}] Processing email for domain: {domain}")
|
||||
|
||||
try:
|
||||
# Entkomprimieren, falls komprimiert
|
||||
if compressed:
|
||||
email_bytes = base64.b64decode(email_content)
|
||||
email_content = gzip.decompress(email_bytes).decode('utf-8')
|
||||
else:
|
||||
email_content = base64.b64decode(email_content).decode('utf-8')
|
||||
|
||||
# An Postfix lokal weiterleiten (Port 25, kein TLS)
|
||||
with smtplib.SMTP(SMTP_HOST, SMTP_PORT) as smtp:
|
||||
smtp.sendmail('lambda@andreasknuth.de', f'inbox@{domain}', email_content)
|
||||
logger.info(f"[{request_id}] Email forwarded to Postfix for {domain}")
|
||||
|
||||
Reference in New Issue
Block a user