Giter Club home page Giter Club logo

telegram-mailer's Introduction

Telegram mailer

Telegram mailer is a web-application that allows sending messages to list of users from a number of accounts that you have connected to it, so that you don't have to do it manually or worry about ban. It is a great tool for automation of mail distribution for your customer base via telegram.

Getting started

Requirements

  • Python 3
  • MongoDB 3.2+
  • Nginx/Apache
  • 1+ telegram accounts

Installation

Clone repository

git clone https://github.com/30mb1/Telegram-mailer.git
cd Telegram-mailer

Create virtual environment and install requirements.

virtualenv -p python3 venv
source venv/bin/activate
pip install -r requirements.txt

Set up proxy server (example for nginx):

  • Create new configuration file in save it in /etc/nginx/sites-available/your_app.conf

    Content of your_app.conf:

    server {
        listen 80;
        server_name some_domain.com;
     
        root /path/to/your_app;
     
        access_log /path/to/your_app/logs/access.log;
        error_log /path/to/your_app/logs/error.log;
     
        location / {
            proxy_set_header X-Forward-For $proxy_add_x_forwarded_for;
            proxy_set_header Host $http_host;
            proxy_redirect off;
            if (!-f $request_filename) {
                proxy_pass http://127.0.0.1:8000; # you can choose another port
                break;
            }
        }
    }
    
  • Create symbol link for sites-enabled:

    sudo ln -s /etc/nginx/sites-available/your_app.conf /etc/nginx/sites-enabled/
    
  • Check configuration for mistakes:

    nginx -t
    
  • If it is ok, reload nginx.

    service nginx reload
    

Now you can run application locally with gunicorn, using nginx for handling external requests and redirecting them.

Setting up

Application use telegram client api, so that we need api keys. Follow instructions on this page to get api_id and api_hash. You then need to install them in app, using initialize.py module:

> cd Telegram-mailer
> source venv/bin/activate
> python initialize.py
Enter api_id:
YOUR_API_ID
Enter api_hash:
YOUR_API_HASH

Now you can run application and check it locally or from external address that we specified in .conf file.

cd Telegram-mailer
source venv/bin/activate
# choose port, that we used in nginx .conf file earlier
gunicorn app:app -b 127.0.0.1:8000 -w 8 --threads 8 # you can run it in screen too
# you can set another number of workers or threads, depenging on your system characteristics
# more detailed info you can find for example here
# http://docs.gunicorn.org/en/stable/settings.html

To make program work we need to attach some telegram accounts to it, so program will use them for message delivery. You can do it on account page of our app. There you also can change login-password

http://pix.toile-libre.org/upload/original/1508499881.png

After putting your phone number in form, you will receive a code, that you need to paste in new form, that will appear

http://pix.toile-libre.org/upload/original/1508500245.png

If the code is correct, number will be marked as activated and stay on this page. This account now is added to list that will be used for delivery. It is better to add more accounts, so that chances of their ban will be less, because app use accounts by queue.

Run

To start message distribution go to config page

http://pix.toile-libre.org/upload/original/1508502322.png

Specify a list of users you want deliver your message to in form @tg_username/phone_number and a message. Interval is used for pause before sending next message in order to avoid ban.

Accounts, attached to app would be used by queue when sending messages. It means, that if we have 10 accounts and want to send message to 20 users, the order will be:

acc1 -> user1
pause for some interval
acc2 -> user2
...
acc1 -> user11
acc2 -> user12

While app is sending messages, there will be appropriate window on mailer tab. You should not start a new distribution before the old one is ended, because of ban possibility.

telegram-mailer's People

Contributors

30mb1 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

telegram-mailer's Issues

Not working

I did not quite understand the moment with the creation of the config, so I decided to leave it by default. There you wrote server_name some_domain.com but showed it on a local host. It is also unclear how to indicate the path to my application and the path to the logs.

root / path / to / your_app;
     access_log /path/to/your_app/logs/access.log;
     error_log /path/to/your_app/logs/error.log;
Снимок экрана 2020-04-25 в 00 23 27

Проблемы при добавление аккаунта

Привет. При попытки верифицировать аккаунт, на сервере 500 ошибка, и вот такой лог

[2022-04-07 04:16:13,203] ERROR in app: Exception on /account [POST]
Traceback (most recent call last):
  File "/var/www/bot/Telegram-mailer/venv/lib/python3.8/site-packages/flask/app.py", line 1982, in wsgi_app
    response = self.full_dispatch_request()
  File "/var/www/bot/Telegram-mailer/venv/lib/python3.8/site-packages/flask/app.py", line 1614, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/var/www/bot/Telegram-mailer/venv/lib/python3.8/site-packages/flask/app.py", line 1517, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/var/www/bot/Telegram-mailer/venv/lib/python3.8/site-packages/flask/_compat.py", line 33, in reraise
    raise value
  File "/var/www/bot/Telegram-mailer/venv/lib/python3.8/site-packages/flask/app.py", line 1612, in full_dispatch_request
    rv = self.dispatch_request()
  File "/var/www/bot/Telegram-mailer/venv/lib/python3.8/site-packages/flask/app.py", line 1598, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/var/www/bot/Telegram-mailer/app/views.py", line 136, in account
    client.disconnect()
AttributeError: 'NoneType' object has no attribute 'disconnect'

error when clicking on activate

I do receive the code after a longer wait, but when I click activate I get server error with the below output on the console.

DEBUG:telethon.network.mtproto_sender:Read RPC error: (PhoneMigrateError(...), 'The phone number a user is trying to use for authorization is associated with DC 1.')
DEBUG:telethon.telegram_bare_client:DC error when invoking request, attempting to reconnect at DC 1
Exception in thread ReadThread:
Traceback (most recent call last):
  File "/usr/lib/python3.7/threading.py", line 917, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.7/threading.py", line 865, in run
    self._target(*self._args, **self._kwargs)
  File "/home/chwba/git/Telegram-mailer/venv/lib/python3.7/site-packages/telethon/telegram_client.py", line 951, in _recv_thread_impl
    self._sender.receive(update_state=self.updates)
AttributeError: 'NoneType' object has no attribute 'receive'

DEBUG:telethon.network.mtproto_sender:Handling bad server salt
DEBUG:telethon.network.mtproto_sender:Processing TLObject new_session_created#9ec20908 first_msg_id:long unique_id:long server_salt:long = NewSession
DEBUG:telethon.network.mtproto_sender:Handling RPC result
DEBUG:telethon.network.mtproto_sender:Reading request response
DEBUG:telethon.network.mtproto_sender:Handling RPC result
DEBUG:telethon.network.mtproto_sender:Read RPC error: (PhoneMigrateError(...), 'The phone number a user is trying to use for authorization is associated with DC 1.')
DEBUG:telethon.telegram_bare_client:DC error when invoking request, attempting to reconnect at DC 1
Exception in thread ReadThread:
Traceback (most recent call last):
  File "/usr/lib/python3.7/threading.py", line 917, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.7/threading.py", line 865, in run
    self._target(*self._args, **self._kwargs)
  File "/home/chwba/git/Telegram-mailer/venv/lib/python3.7/site-packages/telethon/telegram_client.py", line 951, in _recv_thread_impl
    self._sender.receive(update_state=self.updates)
AttributeError: 'NoneType' object has no attribute 'receive'

DEBUG:telethon.network.mtproto_sender:Handling bad server salt
DEBUG:telethon.network.mtproto_sender:Processing TLObject new_session_created#9ec20908 first_msg_id:long unique_id:long server_salt:long = NewSession
DEBUG:telethon.network.mtproto_sender:Handling RPC result
DEBUG:telethon.network.mtproto_sender:Reading request response
DEBUG:telethon.network.mtproto_sender:Handling RPC result
DEBUG:telethon.network.mtproto_sender:Read RPC error: (PhoneMigrateError(...), 'The phone number a user is trying to use for authorization is associated with DC 4.')
DEBUG:telethon.telegram_bare_client:DC error when invoking request, attempting to reconnect at DC 4
Exception in thread ReadThread:
Traceback (most recent call last):
  File "/usr/lib/python3.7/threading.py", line 917, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.7/threading.py", line 865, in run
    self._target(*self._args, **self._kwargs)
  File "/home/chwba/git/Telegram-mailer/venv/lib/python3.7/site-packages/telethon/telegram_client.py", line 951, in _recv_thread_impl
    self._sender.receive(update_state=self.updates)
AttributeError: 'NoneType' object has no attribute 'receive'

DEBUG:telethon.network.mtproto_sender:Handling bad server salt
DEBUG:telethon.network.mtproto_sender:Processing TLObject new_session_created#9ec20908 first_msg_id:long unique_id:long server_salt:long = NewSession
DEBUG:telethon.network.mtproto_sender:Handling RPC result
DEBUG:telethon.network.mtproto_sender:Reading request response
DEBUG:telethon.network.mtproto_sender:Handling RPC result
DEBUG:telethon.network.mtproto_sender:Reading request response
DEBUG:telethon.network.mtproto_sender:Read RPC error: (FloodWaitError(...), 'A wait of 82771 seconds is required.')
Exception in thread Thread-2:
Traceback (most recent call last):
  File "/home/chwba/git/Telegram-mailer/venv/lib/python3.7/site-packages/telethon/telegram_client.py", line 238, in invoke
    request, call_receive=self._recv_thread is None
  File "/home/chwba/git/Telegram-mailer/venv/lib/python3.7/site-packages/telethon/telegram_bare_client.py", line 318, in invoke
    raise request.rpc_error
telethon.errors.rpc_errors_303.PhoneMigrateError: (PhoneMigrateError(...), 'The phone number a user is trying to use for authorization is associated with DC 1.')

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.7/threading.py", line 917, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.7/threading.py", line 865, in run
    self._target(*self._args, **self._kwargs)
  File "/home/chwba/git/Telegram-mailer/utils.py", line 15, in make_request
    clients_list[phone].send_code_request(phone)
  File "/home/chwba/git/Telegram-mailer/venv/lib/python3.7/site-packages/telethon/telegram_client.py", line 281, in send_code_request
    SendCodeRequest(phone, self.api_id, self.api_hash))
  File "/home/chwba/git/Telegram-mailer/venv/lib/python3.7/site-packages/telethon/telegram_client.py", line 247, in invoke
    return self.invoke(request)
  File "/home/chwba/git/Telegram-mailer/venv/lib/python3.7/site-packages/telethon/telegram_client.py", line 238, in invoke
    request, call_receive=self._recv_thread is None
  File "/home/chwba/git/Telegram-mailer/venv/lib/python3.7/site-packages/telethon/telegram_bare_client.py", line 318, in invoke
    raise request.rpc_error
telethon.errors.rpc_errors_420.FloodWaitError: (FloodWaitError(...), 'A wait of 82771 seconds is required.')

Exception in thread ReadThread:
Traceback (most recent call last):
  File "/usr/lib/python3.7/threading.py", line 917, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.7/threading.py", line 865, in run
    self._target(*self._args, **self._kwargs)
  File "/home/chwba/git/Telegram-mailer/venv/lib/python3.7/site-packages/telethon/telegram_client.py", line 947, in _recv_thread_impl
    int.from_bytes(os.urandom(8), 'big', signed=True)
  File "/home/chwba/git/Telegram-mailer/venv/lib/python3.7/site-packages/telethon/network/mtproto_sender.py", line 63, in send
    self._send_packet(writer.get_bytes(), request)
  File "/home/chwba/git/Telegram-mailer/venv/lib/python3.7/site-packages/telethon/network/mtproto_sender.py", line 129, in _send_packet
    self.connection.send(cipher_writer.get_bytes())
  File "/home/chwba/git/Telegram-mailer/venv/lib/python3.7/site-packages/telethon/network/connection.py", line 173, in _send_tcp_full
    self.write(writer.get_bytes())
  File "/home/chwba/git/Telegram-mailer/venv/lib/python3.7/site-packages/telethon/network/connection.py", line 215, in _write_plain
    self.conn.write(data)
  File "/home/chwba/git/Telegram-mailer/venv/lib/python3.7/site-packages/telethon/extensions/tcp_client.py", line 66, in write
    self._socket.sendall(data)
BrokenPipeError: [Errno 32] Broken pipe

DEBUG:telethon.network.mtproto_sender:Read RPC error: (FloodWaitError(...), 'A wait of 82746 seconds is required.')
Exception in thread Thread-2:
Traceback (most recent call last):
  File "/home/chwba/git/Telegram-mailer/venv/lib/python3.7/site-packages/telethon/telegram_client.py", line 238, in invoke
    request, call_receive=self._recv_thread is None
  File "/home/chwba/git/Telegram-mailer/venv/lib/python3.7/site-packages/telethon/telegram_bare_client.py", line 318, in invoke
    raise request.rpc_error
telethon.errors.rpc_errors_303.PhoneMigrateError: (PhoneMigrateError(...), 'The phone number a user is trying to use for authorization is associated with DC 1.')

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.7/threading.py", line 917, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.7/threading.py", line 865, in run
    self._target(*self._args, **self._kwargs)
  File "/home/chwba/git/Telegram-mailer/utils.py", line 15, in make_request
    clients_list[phone].send_code_request(phone)
  File "/home/chwba/git/Telegram-mailer/venv/lib/python3.7/site-packages/telethon/telegram_client.py", line 281, in send_code_request
    SendCodeRequest(phone, self.api_id, self.api_hash))
  File "/home/chwba/git/Telegram-mailer/venv/lib/python3.7/site-packages/telethon/telegram_client.py", line 247, in invoke
    return self.invoke(request)
  File "/home/chwba/git/Telegram-mailer/venv/lib/python3.7/site-packages/telethon/telegram_client.py", line 238, in invoke
    request, call_receive=self._recv_thread is None
  File "/home/chwba/git/Telegram-mailer/venv/lib/python3.7/site-packages/telethon/telegram_bare_client.py", line 318, in invoke
    raise request.rpc_error
telethon.errors.rpc_errors_420.FloodWaitError: (FloodWaitError(...), 'A wait of 82746 seconds is required.')

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.