Code Monkey home page Code Monkey logo

telegram-mailgate's Introduction

telegram-mailgate

telegram-mailgate is very similar to gpg-mailgate. This script is a content filter for Postfix to send mails via telegram. It is very minimalistic but it can be useful to receive say outputs from CRON directly to your mobile.

usage: telegram-mailgate.py [-h] [--config CONFIG] [--from FROM]
                            [--queue-id QUEUE_ID] [--raw | --simple-header]
                            to [to ...]

positional arguments:
  to                   the recipients

optional arguments:
  -h, --help           show this help message and exit
  --config CONFIG      use a custom configuration file
  --from FROM          overwrite field "From" from the header. Ignored if
                       --raw is specified.
  --queue-id QUEUE_ID  specify the queue ID of the message for logging
  --raw                include all sections, header and attachments
  --simple-header      include a header in a separate message

Installation

sudo apt update && sudo apt install python3 python3-pip
sudo adduser --system telegram-mailer  # create a specific user to run telegram-mailgate
sudo -u telegram-mailer pip3 install --user python-telegram-bot
sudo cp telegram-mailgate/telegram-mailgate.py /usr/local/bin/
sudo chown telegram-mailer /usr/local/bin/telegram-mailgate.py
sudo chmod 700 /usr/local/bin/telegram-mailgate.py
sudo mkdir /etc/telegram-mailgate
sudo cp telegram-mailgate/{main.cf,logging.cf,aliases} /etc/telegram-mailgate/    

Edit /etc/telegram-mailgate/main.cf to configure your telegram API key. Edit /etc/telegram-mailgate/aliases to configure the mapping between the recipients' addresses and the corresponding chat ID. The format is:

Adam 00000000
Bob 00000001
Charlie 00000002

The format does not support comments nor empty lines.

You can optionally edit /etc/telegram-mailgate/logging.cf to configure the logging. The default logs to syslog.

Postfix configuration

In /etc/postfix/master.cf, add the following process:

# =======================================================================
# telegram-mailgate
telegram-mailgate unix -     n       n       -        -      pipe
  flags= user=telegram-mailer argv=/usr/local/bin/telegram-mailgate.py --simple-header --queue-id $queue_id $recipient

Make sure that whatever user you specify above has permissions to execute telegram-mailgate and python dependencies installed. Of course you can set whatever arguments for the script.

In /etc/postfix/main.cf add telegram-mailgate as a content filter:

content_filter = telegram-mailgate

Restart postfix

# postfix reload

Testing

echo "This is the body of the email" | mail -s "This is the subject line" <my_recipent>

replace <my_recipient> by who ever is listed in the alias file. If local user, you may need to add @ at the end. You can see logs with sudo tail -f /var/log/mail.log.

telegram-mailgate's People

Contributors

plantaquatix avatar

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.