Recently I found the need to have sendmail on one of my servers to send me email notifications, but didn’t want to have sendmail actually installed. So some python and smtplib made for an easy, ‘sendmail compliant’ alternative that I could use with services that interface with sendmail for email notifications. The python script is as follows:
Filed under:#!/usr/bin/env python2 import sys, smtplib SERVER = "smtp.gmail.com" PORT = 465 USER = "email_address_or_username" PASS = "email_password_here" ADMINS = ("list_of_recipients@domain.com",) if __name__ == "__main__": message_text = "" for line in sys.stdin.readlines(): message_text += line server = smtplib.SMTP_SSL(SERVER, PORT) server.set_debuglevel(0) server.login(USER, PASS) server.sendmail(USER, ADMINS, message_text) server.quit()
Tags: email notifications, Linux, Python, scripts, sendmail


