GNU/Linux Procmail / Python Mail Alert Script for Telegram

Small script to send a telegram chat message to a user when new mail arives. Script uses procmail and a small python script to process the message and to send the alert alert message through a telegram bot api.

.procmailrc:| env python ./
.procmailrc:.mail/ sys email httplib urllib Contstants... = ['', ''] = "telegram_botkey" = "telegram_userid" = {"Content-type": "application/x-www-form-urlencoded", "Accept": "text/plain"} = "" = "/bot" + key + "/sendMessage" Read from stdin... = = email.message_from_string(full_msg) Get info from message... = msg['to'] = msg['subject'] = msg['from'] Check if e-mail in list... mailaddr in email_addresses:  if mailaddr in mto:    mrow = "[S6:NewMailAlert] \nFrom: " + mfrom + " \nSubject: " + msubject    params = urllib.urlencode({'chat_id': userid, 'disable_web_page_preview': '1', 'text': mrow})    connectie = httplib.HTTPSConnection(host=hostname, port=443)    connectie.request("POST", uri, params, headers)    resultaat = connectie.getresponse()    if resultaat.status <> 200:      print resultaat.status, resultaat.reason