# # send bulk mail quickly by injecting it directly into # the maildrop # # this works in our postfix environment, YMMV # you will have to take some steps for 'nobody' to be allowed to # start/stop postfix (write a SUID root wrapper, basically). # if you have no clue about the implications DON'T DO IT! # # 2000-11-03, stefan@epy.co.at # import os, time, threading startcommand = '/Zope/mybin/postfixwrapper start' stopcommand = '/Zope/mybin/postfixwrapper stop' lockfile = '/Zope/var/bulkmailhack.lock' injectcommand = '/usr/sbin/sendmail -t -oi -f%s' mailtemplate = 'From: %s\nTo: %s\nPrecedence: bulk\nSubject: %s\n%s\n' def sendMail( mailfrom, addrlist, subject, body, detached=1 ): if detached: t = threading.Thread( None, sender_thread, None, (mailfrom, addrlist, subject, body) ) t.start() return else: ts = time.time() sender_thread( mailfrom, addrlist, subject, body ) tr = time.time() - ts return (tr, len(addrlist)/tr) def sender_thread( mailfrom, addrlist, subject, body ): stop_mta() for mailto in addrlist: p = os.popen( injectcommand % (mailfrom), 'w', 1 ) p.write( mailtemplate % (mailfrom, mailto, subject, body) ) p.close() start_mta() def stop_mta(): while 1: try: os.stat( lockfile ) except: l = open( lockfile, 'wt' ) l.write( 'remove this file if the bulkmailhack appears to hang' ) l.close() os.system( stopcommand ) time.sleep( 5 ) return time.sleep( 15 ) def start_mta(): try: os.unlink( lockfile ) except: pass os.system( startcommand )