Chris
Chris

Reputation: 39

How to send telegram messages that i receive to email

How can i send my messages from telegram to email or another telegram account.For example.I get message from someone and this message also sends to my email.Is there any way to do that?

Upvotes: 2

Views: 5434

Answers (1)

Beppe C
Beppe C

Reputation: 13993

You can process the incoming message, retrieve the text and send an email using a Python api, for example Mailgun which has a free trial:

# define Telegram message handler
dp.add_handler(MessageHandler(Filters.text, main_handler))

def main_handler(update, context):
   content = update.message.text
   from = update.message.from_user

   # send email using Mailgun
   requests.post(
    "https://api.mailgun.net/v3/YOUR_DOMAIN_NAME/messages",
    auth=("api", "YOUR_API_KEY"),
    data={"from": "Telegram Bot <telegrambot@YOUR_DOMAIN_NAME>",
          "to": ["myaccount@gmail.com"],
          "subject": "Telegram msg from " + from,
          "text": content})

Another popular yagmail library which can send emails from your gmail account.

Upvotes: 1

Related Questions