Exemplo n.º 1
0
 def sm_do_send(cls, subject, to_add, context, template_name, reply_to=None):
     try:
         context['unsubscribe_link'] = False  # unable to unsuncrible, example system email
         if context.get("email_token", None):
             context['unsubscribe_link'] = Utils.get_public_url(cls.__UNSUBSCRIBE_LINK + context.get("email_token"))
         context['public_base'] = Utils.get_public_url()
         context['privacy_link'] = Utils.get_public_url(cls.__PRIVACY_LINK)
         context['support_link'] = Utils.get_public_url(cls.__SUPPORT_LINK)
         # bcc = context.get("bcc", [])
         if to_add[0] == settings.BCC_EMAIL_ADDRESS:
             pass
         else:
             if settings.ALLOWED_EMAILS != "*":
                 if settings.ALLOWED_EMAILS:
                     to_add = [settings.ALLOWED_EMAILS]
                 else:
                     Utils.log("settings.ALLOWED_EMAILS is empty")
                     return
         mail = TemplateEmail(
             subject=subject,
             template=template_name,
             context=context,
             from_email=u"{} Support <{}>".format(cls.__BRAND_NAME, settings.SUPPORT_EMAIL),
             to=to_add,
             # bcc=bcc,
             headers={"Reply-To": reply_to or cls.__REPLY_TO},
         )
         mail.send()
     except Exception as e:
         cls.log_exception(e)
Exemplo n.º 2
0
 def verify_email(cls, token, email_add, *args, **kwargs):
     """
     Verify email address and active account
     """
     template_name = kwargs.pop('template', 'verify')
     template_name = get_template(template_name)
     uid = kwargs.pop('uid', 'activation')
     subject = "Welcome to {}".format(cls.__BRAND_NAME)
     user_email = email_add
     verify_link = ""
     verify_link = Utils.get_public_url('/verify/{}/{}'.format(uid, token))
     context = {
         'verify_link': verify_link,
         'email': email_add,
         'password': kwargs.pop('password', None)
     }
     cls._sm_send_email(subject, [user_email], context, template_name, False, False)
Exemplo n.º 3
0
 def reset_link(cls, token, uid, *args, **kwargs):
     """
     Send reset password link
     """
     user = kwargs.get('user', None)
     user_id = kwargs.get('user_id', None)
     if not user and not user_id:
         raise EmailError('Please provide user or user id param.')
     if not user:
         user = UserService.get_user(user_id)
     template_name = get_template('reset-password')
     subject = 'Somebody requested a new password for your {} account'.format(cls.__BRAND_NAME)
     user_email = '"%s" <%s>' % (user.get_full_name(), user.email)
     link = Utils.get_public_url('/password/reset/{}/{}'.format(uid.decode('utf-8'), token))
     context = {
         'reset_link': link,
         'username': user.email
     }
     cls._sm_send_email(subject, [user_email], context, template_name, False, False)