Exemplo n.º 1
0
def send_change_password_email(
        request, profile, email=None, subject=None,
        text_body=None, html_body=None, discussion=None,
        sender_name=None, welcome=False, immediate=False):
    mailer = get_mailer(request)
    localizer = request.localizer
    route_maker = create_get_route(request, discussion)
    data = dict(
        assembl="Assembl", name=profile.name,
        confirm_url=get_global_base_url() + route_maker(
            'welcome' if welcome else 'do_password_change',
            token=password_change_token(profile)))
    sender_email = config.get('assembl.admin_email')
    if discussion:
        data.update(dict(
            discussion_topic=discussion.topic,
            discussion_url=discussion.get_url()))
        sender_name = sender_name or discussion.topic
    if sender_name:
        sender_name = normalize_email_name(sender_name)
        sender = '"%s" <%s>' % (sender_name, sender_email)
        sender_name = Header(sender_name, 'utf-8').encode()
        if len(sender) > 255:
            sender = sender_email
    else:
        sender = sender_email
    subject = (subject or localizer.translate(
        _("Request for password change"))).format(**data)
    #subject = Header(subject, 'utf-8').encode()  # Fails in some cases???
    if text_body is None or html_body is not None:
        # if text_body and no html_body, html_body remains None.
        html_body = html_body or localizer.translate(_(u"""<p>Hello, {name}!</p>
<p>We have received a request to change the password on your {assembl} account.
Please <a href="{confirm_url}">click here to confirm your password change</a>.</p>
<p>If you did not ask to reset your password please disregard this email.</p>
<p>Best regards,<br />The {assembl} Team</p>
"""))
    text_body = text_body or localizer.translate(_(u"""Hello, {name}!
We have received a request to change the password on your {assembl} account.
To confirm your password change please click on the link below.
<{confirm_url}>

If you did not ask to reset your password please disregard this email.

Best regards,
The {assembl} Team
"""))
    message = Message(
        subject=subject,
        sender=sender,
        recipients=["%s <%s>" % (
            profile.name, email or profile.get_preferred_email())],
        body=text_body.format(**data), html=html_body.format(**data))
    if immediate:
        mailer.send_immediately(message)
    else:
        mailer.send(message)
Exemplo n.º 2
0
 def discussionCreated(self, discussion):
     from assembl.models import Notification
     from ..lib.frontend_urls import FrontendUrls
     from premailer import Premailer
     profile = discussion.creator
     assert profile
     jinja_env = Notification.make_jinja_env()
     (assembl_css, ink_css) = Notification.get_css_paths(discussion)
     request = get_current_request()
     confirm_url = request.route_url(
         'contextual_welcome',
         discussion_slug=discussion.slug,
         ticket=password_change_token(profile))
     template_data = {
         'discussion': discussion,
         'frontendUrls': FrontendUrls(discussion),
         'ink_css': ink_css.read(),
         'assembl_notification_css': assembl_css.read().decode('utf_8'),
         'jinja_env': jinja_env,
         'connection_url': confirm_url,
         'documentation_url': config.get('documentation_url'),
         'admin_email': config.get('admin_email'),
         'admin_name': config.get('admin_name'),
         'admin_org_name': config.get('admin_org_name'),
         'admin_org_url': config.get('admin_org_url'),
     }
     html_template = jinja_env.get_template(
         'notifications/html_new_discussion.jinja2')
     html_body = html_template.render(**template_data)
     html_body = Premailer(html_body, disable_leftover_css=True).transform()
     text_template = jinja_env.get_template(
         'notifications/txt_new_discussion.jinja2')
     text_body = text_template.render(**template_data)
     sender_email = config.get('assembl.admin_email')
     mailer = get_mailer(request)
     localizer = request.localizer
     sender_name = discussion.topic
     sender_name = normalize_email_name(sender_name)
     sender = '"%s" <%s>' % (sender_name, sender_email)
     sender_name = Header(sender_name, 'utf-8').encode()
     if len(sender) > 255:
         sender = sender_email
     subject = localizer.translate(_("Your consultation was created"))
     message = Message(
         subject=subject,
         sender=sender,
         recipients=["%s <%s>" % (
             profile.name, profile.get_preferred_email())],
         cc=aslist(config.get("discussion_creation_cc", "")),
         body=text_body,
         html=html_body)
     mailer.send(message)
Exemplo n.º 3
0
 def discussionCreated(self, discussion):
     from assembl.models import Notification
     from ..lib.frontend_urls import FrontendUrls
     from premailer import Premailer
     profile = discussion.creator
     assert profile
     jinja_env = Notification.make_jinja_env()
     (assembl_css, ink_css) = Notification.get_css_paths(discussion)
     request = get_current_request()
     confirm_url = request.route_url('contextual_welcome',
                                     discussion_slug=discussion.slug,
                                     ticket=password_change_token(profile))
     template_data = {
         'discussion': discussion,
         'frontendUrls': FrontendUrls(discussion),
         'ink_css': ink_css.read(),
         'assembl_notification_css': assembl_css.read().decode('utf_8'),
         'jinja_env': jinja_env,
         'connection_url': confirm_url,
         'documentation_url': config.get('documentation_url'),
         'admin_email': config.get('admin_email'),
         'admin_name': config.get('admin_name'),
         'admin_org_name': config.get('admin_org_name'),
         'admin_org_url': config.get('admin_org_url'),
     }
     html_template = jinja_env.get_template(
         'notifications/html_new_discussion.jinja2')
     html_body = html_template.render(**template_data)
     html_body = Premailer(html_body, disable_leftover_css=True).transform()
     text_template = jinja_env.get_template(
         'notifications/txt_new_discussion.jinja2')
     text_body = text_template.render(**template_data)
     sender_email = config.get('assembl.admin_email')
     mailer = get_mailer(request)
     localizer = request.localizer
     sender_name = discussion.topic
     sender_name = normalize_email_name(sender_name)
     sender = '"%s" <%s>' % (sender_name, sender_email)
     sender_name = Header(sender_name, 'utf-8').encode()
     if len(sender) > 255:
         sender = sender_email
     subject = localizer.translate(_("Your consultation was created"))
     message = Message(subject=subject,
                       sender=sender,
                       recipients=[
                           "%s <%s>" %
                           (profile.name, profile.get_preferred_email())
                       ],
                       cc=aslist(config.get("discussion_creation_cc", "")),
                       body=text_body,
                       html=html_body)
     mailer.send(message)