fix support for channels and supergroups
This commit is contained in:
parent
e59560fafd
commit
358b50857e
11
relay.py
11
relay.py
@ -1,4 +1,4 @@
|
|||||||
import os
|
kimport os
|
||||||
import asyncio
|
import asyncio
|
||||||
from aiosmtpd.controller import Controller
|
from aiosmtpd.controller import Controller
|
||||||
from email.parser import BytesParser
|
from email.parser import BytesParser
|
||||||
@ -35,14 +35,15 @@ class SMTPHandler:
|
|||||||
try:
|
try:
|
||||||
await bot.send_message(chat_id=chat_id, text=telegram_message)
|
await bot.send_message(chat_id=chat_id, text=telegram_message)
|
||||||
print(f"Message sent to Telegram chat ID: {chat_id}")
|
print(f"Message sent to Telegram chat ID: {chat_id}")
|
||||||
except telegram.error.BadRequest:
|
except telegram.error.BadRequest as e:
|
||||||
print(f"Failed to send message to chat ID: {chat_id}. Using default chat ID.")
|
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)
|
await bot.send_message(chat_id=DEFAULT_CHAT_ID, text=telegram_message)
|
||||||
|
|
||||||
return '250 Message accepted for delivery'
|
return '250 Message accepted for delivery'
|
||||||
|
|
||||||
def extract_chat_id(self, email):
|
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:
|
if match:
|
||||||
return match.group(1)
|
return match.group(1)
|
||||||
print(f"Invalid email format: {email}. Using default chat ID.")
|
print(f"Invalid email format: {email}. Using default chat ID.")
|
||||||
@ -56,4 +57,4 @@ if __name__ == '__main__':
|
|||||||
loop = asyncio.get_event_loop()
|
loop = asyncio.get_event_loop()
|
||||||
loop.create_task(start_smtp_server())
|
loop.create_task(start_smtp_server())
|
||||||
print(f"SMTP server started on {SMTP_HOST}:{SMTP_PORT}")
|
print(f"SMTP server started on {SMTP_HOST}:{SMTP_PORT}")
|
||||||
loop.run_forever()
|
loop.run_forever(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user