diff --git a/relay.py b/relay.py index 55ce0c2..def250d 100644 --- a/relay.py +++ b/relay.py @@ -1,4 +1,4 @@ -import os +kimport os import asyncio from aiosmtpd.controller import Controller from email.parser import BytesParser @@ -35,14 +35,15 @@ class SMTPHandler: try: await bot.send_message(chat_id=chat_id, text=telegram_message) print(f"Message sent to Telegram chat ID: {chat_id}") - except telegram.error.BadRequest: - print(f"Failed to send message to chat ID: {chat_id}. Using default chat ID.") + except telegram.error.BadRequest as e: + print(f"Failed to send message to chat ID: {chat_id}. Error: {str(e)}") + print("Attempting to send to default chat ID.") await bot.send_message(chat_id=DEFAULT_CHAT_ID, text=telegram_message) return '250 Message accepted for delivery' def extract_chat_id(self, email): - match = re.match(r'(\d+)@telegram-relay\.local', email) + match = re.match(r'(-?\d+)@telegram-relay\.local', email) if match: return match.group(1) print(f"Invalid email format: {email}. Using default chat ID.") @@ -56,4 +57,4 @@ if __name__ == '__main__': loop = asyncio.get_event_loop() loop.create_task(start_smtp_server()) print(f"SMTP server started on {SMTP_HOST}:{SMTP_PORT}") - loop.run_forever() + loop.run_forever(