A Telegram Bot that forwards chat massages and files as emails. Works in private chats, groups and channels.
This bot is only capable of forwarding text messages, polls, locations, photos, documents, audio files, video files, voice messages, stickers and video notes.
Some of our club members refuse to join the club's private information broadcast Telegram channel. The organizer had to write each message twice. One for Telegram and one for email distribution. This bot fixes the problem by simply sending Telegram messages to a mailing list.
The tool extracts the chat ID from the returned JSON response. Note down your chat ID.
Alternatively, if you don't want to use an untrusted tool, you can visit
https://api.telegram.org/bot${token}/getUpdates and replace ${token} with your HTTP API Token. Find the number
where it reads [...]"chat":{"id":>someNumber< or
{
"ok": true,
"result": [
{
[...],
"message": {
[...],
"chat": {
"id": >someNumber<, ← that is the number you want
[...]
},
[...]
}
}
]
}
The Telegram Bot you have created is just a gateway between Telegram and the actual Service Tg2SMTP. You must start this service in order to retrieve messages and send emails. You'll probably want to run Tg2SMTP on a server either way to guarantee mails get sent instantly.
Before you can start you should know your SMTP provider's hostname/server address/SMTP server, port and authentication mechanisms and constraints as well as your login credentials. Most providers provide a FAQ for common email clients like Outlook, Thunderbird etc.
The following table shows all available configuration properties. Choose either Property or Environment Variable
column depending on your deployment method. Spring, the underlying framework, allows a deployment method independent way
to provide configuration for Tg2SMTP. To do this, write the desired configuration key-value pairs in an
application.properties or application.yml file and place the file next to the .jar file. Spring then reads this
file at startup.
| Property | Environment Variable | Datatype | Default Value | Example Value | Description |
|---|---|---|---|---|---|
| tg2smtp.notification.subject | TG2SMTP_MAIL_SUBJECT | String | "[Telegram] New Message" | The mail's subject line | |
| tg2smtp.notification.to | TG2SMTP_MAIL_TO | String[] | [email protected],[email protected] | Comma-separated list of zero or more mail recipients | |
| tg2smtp.bot.chat-id | TG2SMTP_CHAT_ID | Number[] | 1337420,-0815 | Comma-separated list of zero or more authorized Telegram Chat IDs | |
| tg2smtp.bot.username | TG2SMTP_BOT_USERNAME | String | MyAwesoneTg2SmtpBot | The Bot's username | |
| tg2smtp.bot.token | TG2SMTP_BOT_TOKEN | String | XXXXXXXX:YYYYYYYYY | The Bot's HTTP API Token | |
| tg2smtp.messages.active | TG2SMTP_MESSAGES_ACTIVE | String[] | ALL | TEXT,PHOTO,LOCATION,VIDEO_NOTE | Comma-separated list of Telegram message types1. |
| spring.mail.host | MAIL_HOST | String | localhost | The SMTP server that is used to send mails | |
| spring.mail.port | MAIL_PORT | Number | 587 | The SMTP server's port | |
| spring.mail.username | MAIL_USERNAME | String | [email protected] | The SMTP username for authentication (required if smtp_auth is active) | |
| spring.mail.password | MAIL_PASSWORD | String | d3v | The SMTP password for authentication (required if smtp_auth is active) | |
| spring.mail.properties.mail.smtp.localhost | MAIL_HELO | String | localhost | The well known hostname Tg2SMTP is running on (optional2) | |
| spring.mail.properties.mail.from | MAIL_FROM | String | [email protected] | The email address mails are sent from (optional while smtp_auth is active) | |
| spring.mail.properties.mail.mail.reply.to | MAIL_REPLY_TO | String | Email address the recipient should answer to (optional) | ||
| spring.profiles.active | SPRING_PROFILES_ACTIVE | String | smtp_auth,smtp_tls | smtp_auth, smtp_tls, smtp_auth,smtp_tls or none | Comma-separated list of active Spring profiles (optional) |
Both profiles, smtp_auth and smtp_tls, are active per default, as it is the most common authentication mechanism throughout.
This bot will only forward these messages as stated in the introduction. For the sake of completeness the following list shows the available messages types and their activation key.
| Message Type | Configuration Key |
|---|---|
| Text Messages | TEXT |
| Locations | LOCATION |
| Polls | POLL |
| Photos | PHOTO |
| Documents | DOCUMENT |
| Audio Files | AUDIO |
| Voice Messages | VOICE |
| Video Files | VIDEO |
| Video Notes | VIDEO_NOTE |
| Stickers | STICKER |
Replace the sample configuration and run the command below to start a Tg2SMTP Docker Container.
docker run -d \
-e TG2SMTP_MAIL_SUBJECT="[Telegram] New message" \
-e [email protected],[email protected] \
-e TG2SMTP_CHAT_ID=1337420 \
-e TG2SMTP_BOT_USERNAME=MyAwesoneTg2SmtpBot \
-e TG2SMTP_BOT_TOKEN=XXXXXXXX:YYYYYYYYY \
-e MAIL_HOST=smtp.example.com \
-e MAIL_PORT=587 \
-e [email protected] \
-e MAIL_PASSWORD=s3cr3t \
-e MAIL_HELO=my-host.example.com \
-e [email protected] \
-e [email protected] \
-e SPRING_PROFILES_ACTIVE=smtp_auth,smtp_tls \
kchwr/tg2smtp:latest
Docker Swarm Mode users may configure their stack using Docker Secrets. Just append _FILE to the appropriate
environment variables: MAIL_USER_FILE, MAIL_PASSWORD_FILE, TG2SMTP_MAIL_TO_FILE, TG2SMTP_CHAT_ID_FILE,
TG2SMTP_BOT_USERNAME_FILE, TG2SMTP_BOT_TOKEN_FILE. Keep in mind that only one Tg2SMTP instance with the same
username can register at the Telegram Bot API concurrently.
Apache License 2.0 - Kammerchor Wernigerode e.V. - Built with :heart:
Content type
Image
Digest
Size
99.9 MB
Last updated
over 4 years ago
docker pull kchwr/tg2smtp