class MailProc(SProcess): _index = None _logger = None _mail_service = None _time_service = None _mail = None _main_dev = None def __init__(self,mainDev): super(MailProc, self).__init__() self._index = 0 self._logger = logging.getLogger(str(__name__)) self._mail = Mail(SysConfig.config['mail']['userName'], SysConfig.config['mail']['password']) self._mail.setSender(SysConfig.config['mail']['sender']) self._mail.setSmptServer(SysConfig.config['mail']['smptserver']) self._mail_service = MailService(self) self.registerService(self._mail_service) self._main_dev = mainDev pass def setIndex(self, index): self._index = index pass def getIndex(self): return self._index pass def getMail(self): return self._mail pass
def notStudent(self, senderNameAndEmail): print("NOT STUDENT '{}'".format(senderNameAndEmail["email"])) msg = "Hi! Your mail was not sent from the domain {}. This service exists solely for the".format( HHSTUDENTMAILDOMAIN) mail = Mail(senderNameAndEmail["email"], msg) mail._send()
def deleteStudent(self, senderNameAndEmail): print("DELETE for {}".format(senderNameAndEmail["email"])) state = pd.read_csv("lib/state.csv") mask = state[state.email == senderNameAndEmail["email"]] vask = state[mask] msg = "Deleted the following rows from the database: {}".format( vask.to_html()) mail = Mail(senderNameAndEmail["email"], msg) mail._send() state[~mask].to_csv("lib/state.csv", index=False)
def studentStatus(self, senderNameAndEmail): print("STATUS for {}".format(senderNameAndEmail["email"])) state = pd.read_csv("lib/state.csv") rows = state[state.email == senderNameAndEmail["email"]] if rows.empty: msg = "Hi! The database doesn't have anything at all on you. Cheers!" else: msg = "Hello {}, here's what the database has about you.<br>{}<br>Cheers!".format( senderNameAndEmail["name"].split(" ")[0], rows.to_html()) mail = Mail(senderNameAndEmail["email"], msg) mail._send()
def getMails(self): """ Internal method used to select relevant rows and wrap getMsg in a HTML-template. Returns a list of Mails. """ key_cols = ["courseCode", "examWriteDate"] tmp_df = self.state_df.merge(self.df, on=key_cols) # keep only those rows that have not already been mailed tmp_df = tmp_df[~tmp_df[self.booleanColumn]] # run through filter tmp_df = self.df_filter(tmp_df) # if empty, return empty list if tmp_df.empty: return [] tmp_df["body"] = tmp_df.apply(self.getMsg, axis=1) # Also marks the correct values in state.csv to True shouldMailTo = tmp_df[key_cols + ["email"]] for i in shouldMailTo.iterrows(): mask = (i[1] == self.state_df[key_cols + ["email"]]).all(axis=1) self.state_df.loc[mask, self.booleanColumn] = True set_state_df(self.state_df) return [ Mail(*i[1:]) for i in list(tmp_df[["email", "body"]].itertuples()) ]
def __init__(self,mainDev): super(MailProc, self).__init__() self._index = 0 self._logger = logging.getLogger(str(__name__)) self._mail = Mail(SysConfig.config['mail']['userName'], SysConfig.config['mail']['password']) self._mail.setSender(SysConfig.config['mail']['sender']) self._mail.setSmptServer(SysConfig.config['mail']['smptserver']) self._mail_service = MailService(self) self.registerService(self._mail_service) self._main_dev = mainDev pass
def mail(self, host, success): status = 'up' if success else 'down' mail = DictUtil.copy(self.conf['mail']) mail['subject'] %= status.upper() mail['body'] %= host debug = DebugUtil.mail(self.conf['localhost']['name'], mail) if Mail.sendraw(mail): self.log.info('Mail sent %s' % debug) else: self.log.critical('Mail not sent %s' % debug)
def execute(self): try: self.backup_resources() except Exception: # Replace mysqldump password if existed stack = re.sub('\-\-password=.*\-\-default\-character\-set=', '--password=?????\', \'--default-charcter-set=', traceback.format_exc(), flags=re.MULTILINE) print(stack) # Send mail if some error occured if 'mail_recipient_address' in self.config: mail = Mail(self.config) mail.send( os.path.basename(__file__) + " encountered an error\n", stack) finally: # Restore LocalSettings if succeeded if not self.backup_local_settings_file == None: print("Restoreing LocalSettings file") shutil.copyfile(self.backup_local_settings_file, self.current_local_settings_file) os.remove(self.backup_local_settings_file)
def execute(self): try: self.backup_resources() except Exception: # Replace mysqldump password if existed stack = re.sub('\-\-password=.*\-\-default\-character\-set=' , '--password=?????\', \'--default-charcter-set=' , traceback.format_exc() , flags=re.MULTILINE) print(stack) # Send mail if some error occured if 'mail_recipient_address' in self.config: mail = Mail(self.config) mail.send( os.path.basename(__file__) + " encountered an error\n" , stack) finally: # Restore LocalSettings if succeeded if not self.backup_local_settings_file == None: print("Restoreing LocalSettings file") shutil.copyfile( self.backup_local_settings_file, self.current_local_settings_file) os.remove(self.backup_local_settings_file)
def sms(self, host, allow, packet): i = isinstance(packet['to'], int) targets = [packet['to']] if i else packet['to']['phones'] if not allow: debug = DebugUtil.sms(host, targets, packet['data']) self.log.info('Message dropped %s' % debug) return try: boxes = self.get() if all(d not in packet['data'] for d in self.conf['devices']): boxes = [boxes.pop(0)] for box in boxes: self.post(box, targets, packet['data']) smsfrom = { 'host' : host, 'box' : box } debug = DebugUtil.sms(smsfrom, targets, packet['data']) self.log.info('Message sent %s' % debug) except MyException: if i: self.log.critical('Test message not sent') return mail = DictUtil.copy(self.conf['mail']) mail['to'] = packet['to']['mails'] mail['body'] = packet['data'] debug = DebugUtil.mail(host, mail) if Mail.sendraw(mail): self.log.info('Mail sent %s' % debug) else: self.log.critical('Mail not sent %s' % debug)
def mail(self, up): status = 'up' if up else 'down' mail = DictUtil.copy(self.conf['mail']) mail['subject'] %= status.upper() body = self.mails[status].pop() if len(self.mails[status]) > 0: hosts = ', '.join(self.mails[status]) body = '%s & %s' % (hosts, body) mail['body'] %= body debug = DebugUtil.mail(self.conf['localhost']['name'], mail) if Mail.sendraw(mail): self.log.info('Mail sent %s' % debug) else: self.log.critical('Mail not sent %s' % debug)
def process_message(self, peer, mailfrom, rcpttos, data): ip, _ = peer host = Util.hostname(ip) fr = '(%s, %s)' % (Util.repr(host), Util.repr(mailfrom)) fr = '%s: %s' % (Util.repr('From'), fr) to = ', '.join(map(Util.repr, rcpttos)) if len(rcpttos) > 1: to = '(%s)' % to to = '%s: %s' % (Util.repr('To'), to) msg = message_from_string(data) subject = Util.repr(msg['Subject']) subject = '%s: %s' % (Util.repr('Subject'), subject) debug = '(%s, %s, %s)' % (fr, to, subject) d = {'host': host} self.send(d) packet = self.recv() if packet['allow']: if Mail.send(mailfrom, rcpttos, data): self.log.info('Mail sent %s' % debug) else: self.log.critical('Mail not sent %s' % debug) else: self.log.info('Mail dropped %s' % debug)
return decorated_auth def requires_admin(f): @wraps(f) def decoracted_admin(*args, **kwargs): if not users.isAdmin(): return redirect(url_for('page_routes.index')) return f(*args, **kwargs) return decoracted_admin users = Users() mail = Mail() page_routes = Blueprint('page_routes', __name__, template_folder='templates') @page_routes.before_request def before_request(): if 'username' in session: users.updateLastseen() pass #Main routes @page_routes.route('/') @requires_auth def index():
def __init__(self): self.db = Database() self.mail = Mail() self.rounds = 10
# read config configObj = Config(BASE_PATH) logObj = Log(configObj) logger = logObj.get_logger() #debug print logger.debug('MAIL_ENABLE {}'.format(configObj.MAIL_ENABLE)) logger.debug('MAIL_TO {}'.format(configObj.MAIL_TO)) logger.debug('MAIL_USER {}'.format(configObj.MAIL_USER)) logger.debug('MAIL_HOST {}'.format(configObj.MAIL_HOST)) logger.debug('MAIL_PORT {}'.format(configObj.MAIL_PORT)) logger.debug('LOG_PATH {}'.format(configObj.LOG_PATH)) logger.debug('LOG_FILE {}'.format(configObj.LOG_FILE)) logger.debug('LOG_MAX_SIZE {}'.format(configObj.LOG_MAX_SIZE)) logger.debug('LOG_BACKUP_COUNT {}'.format(configObj.LOG_BACKUP_COUNT)) # argc check if len(sys.argv) != 2: logger.error('Need User') sys.exit(configObj.ERROR_PROC_EXIST) sysuser = sys.argv[1] # initial ddnsObj mailObj = Mail(configObj, logger, sysuser) mailObj.send() # success exit sys.exit(configObj.SUCCESS_EXIT)
def infoMailAdmin(self, mailText, receiver=None): if receiver == None: receiver = self.ownerEmails[0] mail = Mail(receiver, mailText) mail._send()