Coder Social home page Coder Social logo

notmail_bot's Introduction

Notmail Bot

Telegram bot that acts as an email client.

V.0.1.0

Usage Preview

Work in progress

Features

  • Auto check email account and notify news.
  • Friendly interface.
  • Multiple email accounts.
  • Compatible with IMAP protocol. (More in the future).
  • Read email on Telegram, mark as read/unread, archive/delete and much more.

Basic configuration

First of all, we need to know our username and the bot_token. The username could be configure in your Telegram app settings (also known as alias). To get thebot_token is necessary to speak with the @BotFather and introduce the /newbot command. It will ask all necesary data and finally, it will give to you the bot_token also called API Token.

Launch

We can launch in several ways:

Docker Compose

To use docker-compose you need to install on your computer Docker-CE and Docker-compose.

Before running it you need to enter the variables in the new file called .env.

cp .example.env .env
nano .env

Finally, we execute the next command and can start to talk with the bot:

docker-compose up -d

If we update the code, you only need to update it (git pull) and relaunch docker compose with the following command:

git pull
docker-compose up -d --build

Docker

sudo docker build -t notmail_bot .
sudo docker run -d --name Notmail_bot \
    --restart always \
    --env-file .env \
    manuellr/notmail_bot

Python

pip install -r requirements.txt
python notmail_bot.py --config_path my-config/my_config.ini

License

You can consult the contributors in the AUTHORS file or see the contributors of a specific file executing the next script:

git blame -C -C -M -- FILE_TO_CONSULT | \
    sed -e 's/[^(]*(\([^0-9]*\).*/\1/' -e 's/[\t ]*$//' | \
    sort | uniq -c | sort -nr

notmail_bot's People

Contributors

juanrarodriguez18 avatar manuellr avatar reyesch avatar

Stargazers

 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

notmail_bot's Issues

Incorrect default db path

The actual default path cause problems with the docker environment.
The default path should stay in 'static' folder.

Notify new versions of Notmail_Bot

The idea is that if a new version (tag) is released, the bot manager will be notified. To do this, the bot should check daily for new tags.

Mejoras en el sistema con la base de datos

Movimiento de código

Desde utils/database.py

Creo que el archivo recoge demasiada información. Según las buenas prácticas de python dice que cada clase en un archivo facilitando el mantenimiento. Esta sería mi propuesta:

  • class EmailServer debería moverse a repository/emailServer.py
  • class User debería moverse a repository/user.py
  • class Account debería moverse a repository/account.py
  • def parseAccountsToJson debería moverse a repository/account.py
  • def parseJsonToAccounts debería moverse a repository/account.py
  • class DBC a repository/repository.py. De esta forma solo habría que llamar a este método. Igualmente creo que habrá que tocar algo para que sea fácil usarlo desde todos los archivos pero cuando se intente unir más seriamente se verá.

Adicionalmente a esto... ¿sería interesante crear la típica sección domain?. Yo tengo el objeto Message dando por ahí la lata que no se donde ponerlo puesto que es algo que no persiste

Desde config/testdb.py

La verdad es que no había planteado ningún sitio para poner los test por lo que esto habría que discutirlo (tanto lugar como como se hacen). Aquí hay dos formas de hacerlo, a lo dp o a lo go. DP ya sabemos como sería, crear una carpeta denominada tests en la raiz e ir organizando todo el código. En cambio, en go los test se ponen en la misma carpeta que el archivo que quieres probar y con el mismo nombre, por ejemplo, los test de services/email.py estarian en services/emailTest.py. A mi sinceramente la forma que más me convence es la de DP así puedes hacer cosas más genéricas y te centras en leer código pero para gustos... los colores.

Conceptos en general

  • No existe unión entre los Accounts y los EmailServer. Creo que un account debería de soportar varios EmailServer puesto que el protocolo imap (el más usado para leer), no puede enviar mensajes por lo que haría falta otro y sería desde la misma cuenta.
  • No se como funciona la base de datos exactamente pero veo fundamental que haya un id en cada tabla puesto que será lo que le pasaríamos al cliente y nos facilitaría las cosas. Quizás se esté implementando de alguna forma que yo no haya visto.

General

Muy buen diseño, le diste bastantes vueltas la verdad.

Hay una cosa que no acabo de tener clara. ¿Para que poner los getter y los setter?

Unknown error with imap

[26-10-17 18:00:59] p8367 {/home/manolo/GIT/Tmail-bot/services/email.py:71} DEBUG - Checking account: [email protected]:/inbox
Exception in thread Thread-1:
Traceback (most recent call last):
  File "/usr/lib/python3.6/imaplib.py", line 1014, in _command_complete
    typ, data = self._get_tagged_response(tag)
  File "/usr/lib/python3.6/imaplib.py", line 1134, in _get_tagged_response
    self._get_response()
  File "/usr/lib/python3.6/imaplib.py", line 1071, in _get_response
    raise self.abort("unexpected response: %r" % resp)
imaplib.IMAP4.abort: unexpected response: b'@gmail.com designates 209.85.220.180 as permitted sender) [email protected];'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.6/threading.py", line 916, in _bootstrap_inner
    self.run()
  File "/home/manolo/GIT/Tmail-bot/utils/scheduler.py", line 29, in run
    schedule.run_pending()
  File "/usr/lib/python3.6/site-packages/schedule/__init__.py", line 452, in run_pending
    default_scheduler.run_pending()
  File "/usr/lib/python3.6/site-packages/schedule/__init__.py", line 75, in run_pending
    self._run_job(job)
  File "/usr/lib/python3.6/site-packages/schedule/__init__.py", line 129, in _run_job
    ret = job.run()
  File "/usr/lib/python3.6/site-packages/schedule/__init__.py", line 377, in run
    ret = self.job_func()
  File "/home/manolo/GIT/Tmail-bot/services/email.py", line 75, in check
    self.read_email_from_gmail(folder)
  File "/home/manolo/GIT/Tmail-bot/services/email.py", line 84, in read_email_from_gmail
    uids, err = self.__get_uid_list(folder)
  File "/home/manolo/GIT/Tmail-bot/services/email.py", line 116, in __get_uid_list
    return imap_util.get_uid_list(self.mail, folder)
  File "/home/manolo/GIT/Tmail-bot/utils/imap.py", line 101, in get_uid_list
    mail.select(folder, readonly=True)  # Don't mark message as read
  File "/usr/lib/python3.6/imaplib.py", line 740, in select
    typ, dat = self._simple_command(name, mailbox)
  File "/usr/lib/python3.6/imaplib.py", line 1191, in _simple_command
    return self._command_complete(name, self._command(name, *args))
  File "/usr/lib/python3.6/imaplib.py", line 1016, in _command_complete
    raise self.abort('command: %s => %s' % (name, val))
imaplib.IMAP4.abort: command: EXAMINE => unexpected response: b'@gmail.com designates 209.85.220.180 as permitted sender) [email protected];'

Add Docker & DockerCompose

  • Use volume to save database.
  • Auto publish in hub.docker.com
  • Option to build or download from hub.docker.com

Unknown bug

[10-10-17 04:46:55] p27549 {/usr/lib/python3.6/site-packages/telegram/ext/updater.py:286} ERROR - Error while getting Updates: Timed out
[10-10-17 04:46:55] p27549 {/home/manolo/GIT/Tmail-bot/commands/generic.py:22} WARNING - Update "None" caused error "Timed out"
[10-10-17 06:01:00] p27549 {/usr/lib/python3.6/site-packages/telegram/ext/updater.py:286} ERROR - Error while getting Updates: Timed out
[10-10-17 06:01:00] p27549 {/home/manolo/GIT/Tmail-bot/commands/generic.py:22} WARNING - Update "None" caused error "Timed out"
[10-10-17 06:40:59] p27549 {/usr/lib/python3.6/site-packages/telegram/ext/updater.py:286} ERROR - Error while getting Updates: Timed out
[10-10-17 06:40:59] p27549 {/home/manolo/GIT/Tmail-bot/commands/generic.py:22} WARNING - Update "None" caused error "Timed out"

Sched caused bot failed

When the bot is running for a long time, raise a bug that stop the execution.

  File "/home/manolo/GIT/Tmail-bot/services/email.py", line 63 in check
  File "/usr/lib/python3.6/sched.py", line 154 in run
  File "/home/manolo/GIT/Tmail-bot/services/email.py", line 63 in check
  File "/usr/lib/python3.6/sched.py", line 154 in run
  File "/home/manolo/GIT/Tmail-bot/services/email.py", line 63 in check

ImportError: No module named clic

doop@doopserver:~/Notmail_Bot$ python notmail_bot.py --config_path my-config/my_config.ini Traceback (most recent call last): File "notmail_bot.py", line 19, in <module> import click # http://click.pocoo.org/6/ ImportError: No module named click

I alredy installed click with pip

Error when forwarding long messages

When the message is longer than Telegram permit (or I think so), it raise that error:

[11-10-17 13:01:22] {/usr/lib/python3.6/site-packages/telegram/ext/dispatcher.py:280} WARNING - A TelegramError was raised while processing the Update
[11-10-17 13:01:22]  {...../Tmail-bot/commands/generic.py:22} WARNING - Update "{'update_id': 21561, 'callback_query': {'id': '2411788', 'chat_instance': '-52917', 'message': {'message_id': 166, 'date': 1507719631, 'chat': {'id': 590, 'type': 'private', 'username': 'xxxxxxx', 'first_name': 'xxxxxn'}, 'edit_date': 15077cdsc678, 'text': '✂ ¡ÚLTIMOS DÍAS! Liquidación con un 22% de dto. total \n"HP Online - Tienda Estudiantes" <[email protected]> \n(2017-10-11 04:16:46-06:00)--', 'entities': [{'type': 'bold', 'offset': 0, 'length': 54}, {'type': 'email', 'offset': 89, 'length': 16}, {'type': 'italic', 'offset': 109, 'length': 25}], 'photo': [], 'new_chat_members': [], 'new_chat_photo': [], 'delete_chat_photo': False, 'group_chat_created': False, 'supergroup_chat_created': False, 'channel_chat_created': False, 'from': {'id': 32809, 'first_name': 'Tmail-bot', 'is_bot': True, 'username': 'xxxxx_bot'}, 'new_chat_member': None}, 'data': '/email/view/[email protected]/123456/inbox', 'from': {'id': 590, 'first_name': 'xxxxxn', 'is_bot': False, 'username': 'xxxxxxx', 'language_code': 'es-ES'}}}" caused error "Message_too_long"

Add option to be able of create a Calendar event

Se pretende añadir información de los Emails a un calendario. Ésto podría resultar útil para añadir Emails de Eventos, Envíos, Fechas Importantes, etc.

Para ello se usará un enlace externo que te permita añadir la información al calendario sin necesidad de integrarse con la API de ninguno de éstos.

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.