def send_reset_password_mail(user): subject = _('Reset password') recipient_list = [user.email] message = _(""" Hello %(name)s: </br> Please click the link below to reset your password, if not your request, concern your account security </br> <a href="%(rest_password_url)s?token=%(rest_password_token)s">Click here reset password</a> </br> This link is valid for 1 hour. After it expires, <a href="%(forget_password_url)s?email=%(email)s">request new one</a> </br> --- </br> <a href="%(login_url)s">Login direct</a> </br> """) % { 'name': user.name, 'rest_password_url': reverse('users:reset-password', external=True), 'rest_password_token': user.generate_reset_token(), 'forget_password_url': reverse('users:forgot-password', external=True), 'email': user.email, 'login_url': reverse('users:login', external=True), } if settings.DEBUG: logger.debug(message) # send_mail_async.delay(subject, message, recipient_list, html_message=message) send_mail_async(subject, message, recipient_list, html_message=message)
def send_user_created_mail(user): subject = _('Create account successfully') recipient_list = [user.email] message = _(""" Hello %(name)s: </br> Your account has been created successfully </br> <a href="%(rest_password_url)s?token=%(rest_password_token)s">click here to set your password</a> </br> This link is valid for 1 hour. After it expires, <a href="%(forget_password_url)s?email=%(email)s">request new one</a> </br> --- </br> <a href="%(login_url)s">Login direct</a> </br> """) % { 'name': user.name, 'rest_password_url': reverse('users:reset-password', external=True), 'rest_password_token': user.generate_reset_token(), 'forget_password_url': reverse('users:forgot-password', external=True), 'email': user.email, 'login_url': reverse('users:login', external=True), } if settings.DEBUG: try: print(message) except OSError: pass # send_mail_async.delay(subject, message, recipient_list, html_message=message) send_mail_async(subject, message, recipient_list, html_message=message)
def send_server_performance_mail(path, usage, usages): from users.models import User subject = _("Disk used more than 80%: {} => {}").format(path, usage.percent) message = subject admins = User.objects.filter(role=User.ROLE.ADMIN) recipient_list = [u.email for u in admins if u.email] logger.info(subject) send_mail_async(subject, message, recipient_list, html_message=message)
def send_user_created_mail(user): subject = '用户开通' recipient_list = [user.email] message = ''' 【devops】:你在devops注册成功,用户名:{},初始密码:{},请请尽快登录平台修改密码。 '''.format(user.username, user.password) if settings.DEBUG: logger.debug(message) else: send_mail_async(subject, message, '*****@*****.**', recipient_list)
def send_user_rest_password_mail(user): subject = '密码重置' recipient_list = [user.email] message = ''' 【devops】:你的密码已被管理员重置, 新密码:{},请请尽快登录平台修改密码。 '''.format(user.password) if settings.DEBUG: logger.debug(message) else: send_mail_async(subject, message, '*****@*****.**', recipient_list)
def send_mail_common(subject, message, recipient_list): try: debug = settings.DEBUG email_from = settings.EMAIL_FROM if debug: logger.debug(message) else: send_mail_async(subject, message, email_from, recipient_list) except KeyError: logger.error('配置文件DEBUG,或者EMAIL_FROM值缺失') except Exception as e: logger.error('发送邮件失败:', e)
def send_reset_ssh_key_mail(user): subject = _('SSH Key Reset') recipient_list = [user.email] message = _(""" Hello %(name)s: </br> Your ssh public key has been reset by site administrator. Please login and reset your ssh public key. </br> <a href="%(login_url)s">Login direct</a> </br> """) % { 'name': user.name, 'login_url': reverse('users:login', external=True), } if settings.DEBUG: logger.debug(message) # send_mail_async.delay(subject, message, recipient_list, html_message=message) send_mail_async(subject, message, recipient_list, html_message=message)