def send_mobile_experience_reminder(recipient, full_name): url = absolute_reverse("login") params = { "full_name": full_name, "url": url, 'url_prefix': get_static_url_prefix(), } message_plaintext = render_to_string( 'registration/email/mobile_signup_reminder.txt', params) message_html = render_to_string( 'registration/email/mobile_signup_reminder.html', params) subject = ugettext('Visit CommCareHQ on your computer!') try: send_html_email_async.delay(subject, recipient, message_html, text_content=message_plaintext, email_from=settings.DEFAULT_FROM_EMAIL) except Exception: logging.warning("Can't send email, but the message was:\n%s" % message_plaintext) raise
def send_domain_registration_email(recipient, domain_name, guid, full_name, first_name): registration_link = 'http://' + get_site_domain() + reverse( 'registration_confirm_domain') + guid + '/' params = { "domain": domain_name, "pricing_link": PRICING_LINK, "registration_link": registration_link, "full_name": full_name, "first_name": first_name, "forum_link": FORUM_LINK, "wiki_link": WIKI_LINK, 'url_prefix': get_static_url_prefix(), } message_plaintext = render_to_string( 'registration/email/confirm_account.txt', params) message_html = render_to_string('registration/email/confirm_account.html', params) subject = ugettext('Activate your CommCare project') try: send_html_email_async.delay(subject, recipient, message_html, text_content=message_plaintext, email_from=settings.DEFAULT_FROM_EMAIL) except Exception: logging.warning("Can't send email, but the message was:\n%s" % message_plaintext)
def activation_24hr_reminder_email(): """ Reminds inactive users registered 24 hrs ago to activate their account. """ request_reminders = RegistrationRequest.get_requests_24hrs_ago() for request in request_reminders: user = WebUser.get_by_username(request.new_user_username) registration_link = 'http://' + get_site_domain() + reverse( 'registration_confirm_domain') + request.activation_guid + '/' email_context = { "domain": request.domain, "registration_link": registration_link, "full_name": user.full_name, "first_name": user.first_name, 'url_prefix': get_static_url_prefix(), } message_plaintext = render_to_string( 'registration/email/confirm_account_reminder.txt', email_context) message_html = render_to_string( 'registration/email/confirm_account.html', email_context) subject = ugettext('Reminder to Activate your CommCare project') send_html_email_async.delay( subject, request.new_user_username, message_html, text_content=message_plaintext, email_from=settings.DEFAULT_FROM_EMAIL )
def send_account_confirmation(commcare_user): from corehq.apps.hqwebapp.tasks import send_html_email_async from corehq.apps.users.views.mobile import CommCareUserConfirmAccountView url = absolute_reverse(CommCareUserConfirmAccountView.urlname, args=[commcare_user.domain, commcare_user.get_id]) template_params = { 'domain': commcare_user.domain, 'username': commcare_user.raw_username, 'url': url, 'url_prefix': get_static_url_prefix(), 'hq_name': commcare_hq_names()['commcare_hq_names']['COMMCARE_HQ_NAME'] } lang = guess_domain_language(commcare_user.domain) with override(lang): text_content = render_to_string( "registration/email/mobile_worker_confirm_account.txt", template_params) html_content = render_to_string( "registration/email/mobile_worker_confirm_account.html", template_params) subject = _( f'Confirm your CommCare account for {commcare_user.domain}') send_html_email_async.delay(subject, commcare_user.email, html_content, text_content=text_content, email_from=settings.DEFAULT_FROM_EMAIL)
def send_mass_emails(email_for_requesting_user, real_email, subject, html, text): if real_email: recipients = [{ 'username': h['username'], 'email': h['email'] or h['username'], 'first_name': h['first_name'] or 'CommCare User', } for h in UserES().web_users().run().hits] else: recipients = [{ 'username': email_for_requesting_user, 'email': email_for_requesting_user, 'first_name': 'CommCare User', }] successes = [] failures = [] for recipient in recipients: context = recipient context.update({ 'url_prefix': get_static_url_prefix() }) html_template = Template(html) text_template = Template(text) text_content = render_to_string("hqadmin/email/mass_email_base.txt", { 'email_body': text_template.render(Context(context)), }) html_content = render_to_string("hqadmin/email/mass_email_base.html", { 'email_body': html_template.render(Context(context)), }) try: send_HTML_email(subject, recipient['email'], html_content, text_content=text_content) successes.append((recipient['username'], None)) except Exception as e: failures.append((recipient['username'], e)) message = ( "Subject: {subject},\n" "Total successes: {success_count} \n Total errors: {failure_count} \n" "".format( subject=subject, success_count=len(successes), failure_count=len(failures)) ) send_html_email_async( "Mass email summary", email_for_requesting_user, message, text_content=message, file_attachments=[ _mass_email_attachment('successes', successes), _mass_email_attachment('failures', failures)] )