def send_mail(emails, mailer_cfg, wait=None, interactive=False): mailer = Mailer( mailer_cfg['mail_host'], user=mailer_cfg['mail_user'], passwd=mailer_cfg['mail_pass'] ) mailer.connect() c = 0 start_time = time.time() elen = len(emails) for mail in emails: c += 1 try: mailer.send_email(**mail) except Exception as e: print(e) print("[%s/%s] Exception for '%s'." % (c, elen, mail['to'])) continue if interactive: print("[%s/%s] Sent email to '%s'." % (c, elen, mail['to'])) if wait: time.sleep(wait) if interactive: end_time = time.time() diff = end_time - start_time mps = elen / diff print("Mailing took %.2f seconds. %.2f mails per second." % (diff, mps)) mailer.disconnect()
def send_mail(emails, mailer_cfg, wait=None, interactive=False): mailer = Mailer(mailer_cfg['mail_host'], user=mailer_cfg['mail_user'], passwd=mailer_cfg['mail_pass']) mailer.connect() c = 0 start_time = time.time() elen = len(emails) for mail in emails: c += 1 try: mailer.send_email(**mail) except Exception as e: print(e) print("[%s/%s] Exception for '%s'." % (c, elen, mail['to'])) continue if interactive: print("[%s/%s] Sent email to '%s'." % (c, elen, mail['to'])) if wait: time.sleep(wait) if interactive: end_time = time.time() diff = end_time - start_time mps = elen / diff print("Mailing took %.2f seconds. %.2f mails per second." % (diff, mps)) mailer.disconnect()
ppau_secretary = config.get('ppau_secretary') inform_secretary = config.get('inform_secretary') or False print("Connecting to database at {}:{}...".format(mongodb_server, mongodb_port)) mongo_connection = Connection(mongodb_server, mongodb_port) mongo_member_collection = mongo_connection.ppau.members # Database = "ppau". Collection = "members" mongo_auth_collection = mongo_connection.ppau.authentication mongo_oldcsv_collection = mongo_connection.ppau.oldcsv print("Reading email templates...") mail_template_new = open("mail-new.txt", 'r').read() mail_template_update = open("mail-update.txt", 'r').read() print("Connecting to mailer at {}...".format(mail_server)) mailer = Mailer(mail_server, user=mail_user, passwd=mail_pass) mailer.connect() print("Done!") def auth(data): user = data['username'] passwd = sha256(data['password'].encode()).hexdigest() return mongo_auth_collection.find_one({ "username": user, "password": passwd }) MAX_AUTO_RECONNECT_ATTEMPTS = 5 def mongo_safe_insert(collection, data): ''' Insert member data into database and wait for commit.