def test_batch_send_empty_recs(self, mock_refresh): server = SMTPServer() try: server.batch_send("sender", [], "msg", {}) except: pass self.assertFalse(mock_refresh.called)
def __init__(self, *args, **kwargs): self.ssl_out_only = False if kwargs.has_key('ssl_out_only'): self.ssl_out_only = kwargs.pop('ssl_out_only') self.debug = False if kwargs.has_key('debug'): self.debug = kwargs.pop('debug') kwargs['credential_validator'] = StoreCredentials() SMTPServer.__init__(self, *args, **kwargs)
def __init__(self, *args, **kwargs): self.ssl_out_only = False if 'ssl_out_only' in kwargs: self.ssl_out_only = kwargs.pop('ssl_out_only') self.debug = False if 'debug' in kwargs: self.debug = kwargs.pop('debug') if kwargs['credential_validator'] is None: kwargs['credential_validator'] = StoreCredentials() SMTPServer.__init__(self, *args, **kwargs)
def test_batch_send_retries(self, mock_refresh): server = SMTPServer() server.set_retries(3) server.set_retries_interval(0) try: server.batch_send("sender", ["rec1"], "msg", {}) except: pass calls = [call(), call(), call()] mock_refresh.assert_has_calls(calls, any_order=True)
def test_batch_send(self, mock_refresh): server = SMTPServer() server.set_retries(0) try: server.batch_send("sender", ["rec1"], "msg", {}) except: pass mock_refresh.assert_called()
def should_skip(recipient, notified): """ Should recipient be skipped? """ if not is_valid_email(recipient): cfg.log.info("Ignoring %s (malformed email)" % recipient) return True if recipient in notified: cfg.log.info("Ignoring %s (already in notified list)" % recipient) return True return False if __name__ == "__main__": server = SMTPServer() cfg.log.info(">> Sending batch emails with message:") (subject, body_txt, body_html) = read_parse_msg(cfg.MSG_FILE) cfg.log.info("Message Subject: %s" % subject) cfg.log.info("Message Text: %s" % body_txt) cfg.log.info("Message HTML: %s" % body_html) notified = read_already_notified(cfg.NOTIFIED_FILE) all_recipients_list = read_recipients_lists(cfg.RECIPIENTS_DIR) mail_count = 0 total_count = 0 recipients_batch = [] start_time = time.time() for rec in all_recipients_list: total_count += 1 recipient = rec.strip().lower()
import sys from smtp_server import SMTPServer def console_setting(key=''): print(key) if __name__ == '__main__': if len(sys.argv) > 2: console_setting() if len(sys.argv) == 2: if sys.argv[1] in ('-h', '-help', '--help', '?', '-?'): console_setting(sys.argv[1]) port = int(sys.argv[1]) else: port = 25 server = SMTPServer() print('server start') server.socket_accept()