> Am 10.12.2014 um 20:17 schrieb Peter Volkov <p...@gentoo.org>: > > We use smtplib in python to send mail through postfix.
I attach a very simple example which I use in Zabbix, writtien in Python. Best wishes Christian #!/usr/bin/env python2.7 import os import sys import smtplib import time import hashlib import datetime from email.MIMEText import MIMEText from email.Utils import formatdate host = "mx.example.com" port = 25 def test_smtp(hashobj): text_subtype = 'plain' fromaddr = "zab...@mon.example.com" toaddrs = [„zabbixt...@example.com"] content = hashobj.hexdigest() subject = os.path.basename(sys.argv[0]).split(".")[0] con = smtplib.SMTP(host, port) if len(sys.argv) > 1 and sys.argv[1] == "debug": con.set_debuglevel(1) msg = MIMEText(content, text_subtype) msg['Date'] = formatdate() msg['Subject'] = subject msg['From'] = fromaddr msg['To'] = toaddrs[0] try: con.sendmail(fromaddr, toaddrs, msg.as_string()) con.quit() except: # we could not deliver mail! Force trigger time.sleep(10) finally: con.close() def main(): h = hashlib.md5() h.update(str(datetime.datetime.now())) ts = time.time() test_smtp(h) te = time.time() return te-ts if __name__ == "__main__": print main() sys.exit(os.EX_OK) # vim: ts=4 sw=4 expandtab -- Bachelor of Science Informatik Erlenwiese 14, 36304 Alsfeld T: +49 6631 78823400, F: +49 6631 78823409, M: +49 171 9905345 USt-IdNr.: DE225643613, http://www.roessner-network-solutions.com
signature.asc
Description: Message signed with OpenPGP using GPGMail