Use Case: SMTP to Telegram

Telegram is an application for Android and iOS that works as chat client for messaging.

Bots are third-party applications that run inside Telegram. Users can interact with bots by sending them messages, commands and inline requests. You control your bots using HTTPS requests to Telegram’s Bot API.

The concept is to use VMR to control a Telegram bot to send Telegram messages to recipients.

You can register a Telegram bot. Once registered, the bot will have a name and token string. You can use the token string to control the Bot via the HTTPS API.

For our testing, we have a Telegram Bot called @variusmrbot.

Step 1:
To start you need to install Telegram on your mobile phone. You can get the application Here

Step 2:
Open Telegram and click a new message chat. Search your bot by its name, eg. @variusmrbot. Send a new Telegram message to the bot. In order for the bot to be able to send messages to you, you will need to first send a  message to the bot.

Step 3:
Open a browser and enter the URL https://api.telegram.org/<%tokenstring%>/getupdates. Replace <%tokenstring%> with the token string of your bot. 

The response includes information of the last message received. We are interested in the “id” field. In the example below, the id field is 0000000000. This is your Telegram chat_id. In this article, we will send a telegram message to your chat_id.

"message":{"message_id":58,"from":{"id":0000000000,"is_bot":false,"first_name":"James","username":"jamescloud","language_code":"en"},"chat":{"id":0000000000,"first_name":"James","username":"jamescloud","type":"private"},"date":1654499996,"text":"Test"}}]}

Step 4:
From VMR’s web interface, access Outbound Profiles > HTTP Profiles.
Create a HTTP Profile with Base URL https://api.telegram.org/<%tokenstring%>/sendMessage. 
Replace <%tokenstring%> with the token string of your bot.

HTTP Profile Base URL

Step 5:
Add the parameters with the chat_id and text similar to below. Replace the value of the “chat_id” field with your chat_id. We have configured the Telegram bot to send message to your chat_id.

HTTP Profile Telegram Mappings

Step 6:
From VMR’s web interface, access Message Processing > Transmission Actions.
Create a Transmission Action that points to the Telegram HTTP profile that we have created in Step 4. 

Telegram Transmission Action

Step 7:
From VMR’s web interface, access Message Processing > Inbound Filters.
Configure an inbound SMTP filter with Transmission Action as “Telegram”.

Email to Telegram

Step 8:
From the web interface, access Control Panel.
Stop and Start the service for the settings to take effect.
Now you are all ready to send a email to VMR’s SMTP Server and convert it to Telegram message.