def save(self, uid): mail = self.get_argument('mail') name = self.get_argument('name') pwd = self.get_argument('pwd', '') role = self.get_argument('role') salt = gen_salt() if re.match(r'^([0-9a-zA-Z]([-\.\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,9})$', mail) is None: self.write(dict(error_msg='invalid mail')) return #logging.info('uid:%s, mail:%s, pwd:%s, role:%s' % (uid, mail, '***', role)) user = self.db.user.find_one({'_id': ObjectId(uid)}) if uid else {} insert = '_id' not in user user.update({ 'mail': mail, 'name': name, 'role': int(role), }) if insert: plain_pwd = gen_salt() pwd = hash_pwd(plain_pwd, mail) if pwd: user.update({ 'salt':salt, 'pwd': hash_pwd(pwd, salt), }) if insert: user['created_at'] = time.time() user['created_by'] = self.m user['valid'] = True try: self.db.user.save(user) if insert: send_mail(mail, 'Your New Account At %s' % self.request.host, 'Hi, %s!<br>' % name + 'a new accont has been created for you. <br>' + 'Website: %s<br>' % self.request.host + 'Username: %s<br>' % mail + 'Password: %s<br>' % plain_pwd + 'Modify your password once you login. <br>' + 'Thanks.', ) self.write(dict(ok=1)) except DuplicateKeyError: self.write(dict(error_msg='duplicate mail'))
def send_reg_mail(receiver): subject = "qiv5注册邮件" content = ''' 恭喜您注册qiv5.com成功,请点击以下链接激活您的账户: <a href="http://qiv5.com">http://qiv5.com</a> ''' send_mail(receiver=receiver, subject=subject, content=content) # send_reg_mail(["*****@*****.**"])
def post(self): mail = self.get_argument('mail') if re.match(r'^([0-9a-zA-Z]([-\.\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,9})$', mail) is None: self.write(dict(error_msg='invalid mail')) return name = mail.split('@')[0] salt = gen_salt() plain_pwd = gen_salt() pwd = hash_pwd(hash_pwd(plain_pwd, mail), salt) user = { 'mail': mail, 'name': name, 'role': 102, 'salt': salt, 'pwd': pwd, 'created_at': time.time(), 'created_by': 'signup', 'valid': True, } try: self.db.user.save(user) send_mail(mail, 'Your New Account At %s' % self.request.host, 'Hi, %s!<br>' % name + 'a new accont has been created for you. <br>' + 'Website: %s<br>' % self.request.host + 'Username: %s<br>' % mail + 'Password: %s<br>' % plain_pwd + 'Modify your password once you login. <br>' + 'Thanks.', ) self.write(dict(url=self.get_next_url(user['role']))) except DuplicateKeyError: self.write(dict(error_msg='duplicate mail'))
import lib.mail as mail import datetime if __name__ == "__main__": mail_list = [{ "date": "星期天", "users": ["*****@*****.**"], }, { "date": "星期一", "users": ["*****@*****.**"], }, { "date": "星期二", "users": ["*****@*****.**"], }, { "date": "星期三", "users": ["*****@*****.**"], }, { "date": "星期四", "users": ["*****@*****.**"], }] weekday = datetime.date.today().isoweekday() print(weekday) weekday = (weekday + 1) % 7 if weekday <= len(mail_list) and weekday != 0: print(mail_list[weekday - 1]) info = dict(mail_list[weekday - 1]) content = u"今天%s, 明天记得早盘检查" % info["date"] mail.send_mail(users=list(info["users"]), "每日提醒", content)
def sending_mail(self, mailto, message): mail.send_mail(mailto, message)