def on_after_save(request, user): user.is_active = False user.set_password(request.POST['password']) # Email verification key = randstr(32) while User.objects.filter(verification_key=key).exists(): key = randstr(32) user.verification_key = key send_mail( title=_('Welcome to MootiroMaps'), receivers=[user.email], message=_(''' Hello, {name}. Before using our tool, please confirm your e-mail visiting the link below. {verification_url} Thanks, the IT3S team. ''').format(name=user.name, verification_url=request.build_absolute_uri( reverse('user_verification', args=(key,)))) ) user.save() redirect_url = reverse('user_check_inbox') return {'redirect': redirect_url}
def send_role_change_notification(user, current_role, deactivated=False): context = { 'user': user, 'current_role': current_role, 'deactivated': deactivated, 'company': user.get_company() } if deactivated: context['new_role'] = 'inactive' elif user.is_company_admin: context['new_role'] = 'admin' elif user.is_named: context['new_role'] = 'named' else: context['new_role'] = 'community' send_mail(subject_template_name='emails/promotion/role_admin_subject.txt', email_template_name='emails/promotion/role_admin.txt', to_email=user.email, context=context, html_email_template_name='emails/promotion/role_admin.html', bcc=settings.RECIPIENT_NEW_NOTIFICATIONS) track_sent_emails( user=user, alert_type='send_role_change_notification', emails=[user.email, settings.RECIPIENT_NEW_NOTIFICATIONS])
def handle(self, *args, **options): named_users = UserProfile.objects.filter(crm_type='named') open_tickets = [] for user in named_users: tickets = Ticket.objects.filter(created_by=user, date_added__gte=datetime.datetime.now().replace(hour=0, minute=0, second=0)).exclude(assigned_to__isnull=True,status="closed",answers_no=0) for ticket in tickets: open_tickets.append(ticket) user = UserProfile.objects.get(email=settings.EMAIL_OF_REPORTING_PERSON) context = { 'base_url': get_base_url(), 'user': user, 'open_tickets': open_tickets, } logger.info(u'Daily notification sent to staff {}'.format(user.email)) send_mail( subject_template_name='emails/reminders/open_tickets_status_subject.txt', email_template_name='emails/reminders/open_tickets_status.txt', to_email=user.email, context=context, html_email_template_name='emails/reminders/open_tickets_status.html' )
def notify_company_admin(new_user): company_emails = UserProfile.objects.filter( is_company_admin=True).values_list('email', flat=True) email_suffixes = {email.split('@')[1]: email for email in company_emails} if new_user.email.split('@')[1] in email_suffixes.keys( ) and new_user.email.split('@')[1] not in [ 'gmail.com', 'yahoo.com', 'hotmail.com' ]: to_email = email_suffixes[new_user.email.split('@')[1]] admin = UserProfile.objects.get(email=to_email) send_mail( subject_template_name= 'emails/new_user/new_user_company_admin_subject.txt', email_template_name='emails/new_user/new_user_company_admin.txt', to_email=to_email, context={ 'user': new_user, 'admin': admin }, html_email_template_name= 'emails/new_user/new_user_company_admin.html', bcc=settings.BCC) log_emails( u'Alert Sent: Notify Company Admin about new user, New user: {}, Admin: {}, Added: {}' .format(new_user, to_email, timezone.now()))
def send_mail_async(title='', message='', sender='', receivers=[], html=False): """Send an email asynchronously using the task manager.""" send_mail(title=title, message=message, sender=sender, receivers=receivers, html=html)
def handle(self, *args, **options): staff_users = UserProfile.objects.filter( is_active=True, crm_type__in=[constants.STAFF, constants.ADMIN, constants.MANAGER] ) for user in staff_users: tickets = Ticket.objects.filter( assigned_to=user, is_deleted=False, status__in=['pending', 'inprogress', 'assigned']).order_by('date_modified') named_tickets = [] community_tickets = [] if not tickets: continue for ticket in tickets: if ticket.owned_by.is_named: if not ticket.issue_type: logger.error('Named ticket without issue type: {}'.format(ticket.id)) ticket.support_plan = crm_interface.get_support_plan(ticket.owned_by) if not ticket.support_plan or not ticket.support_plan['support_plan']: logger.error('Named ticket without support plan: {}'.format(ticket.id)) ticket.is_overdue = ticket.date_modified < timezone.now() - timedelta(days=10) named_tickets.append(ticket) else: community_tickets.append(ticket) context = { 'base_url': get_base_url(), 'user': user, 'community_tickets': community_tickets, 'named_tickets': named_tickets, 'tickets_count': tickets.count() } logger.info(u'Daily digest sent to staff {}'.format(user.email)) send_mail( subject_template_name='emails/reminders/staff_digest_subject.txt', email_template_name='emails/reminders/staff_digest.txt', to_email=user.email, context=context, html_email_template_name='emails/reminders/staff_digest.html', bcc=settings.DEFAULT_RECIPIENT_IDLE_TICKET_REMINDERS )
def send_revoke_access_email(user, company): send_mail( subject_template_name= 'emails/deactivate/revoke_access_named_subject.txt', email_template_name='emails/deactivate/revoke_access_named.txt', to_email=user.email, context={'company': company}, html_email_template_name='emails/deactivate/revoke_access_named.html') track_sent_emails(user=user, alert_type='send_revoke_access_email', emails=user.email)
def send_deactivation_email(user): send_mail( subject_template_name= 'emails/deactivate/deactivate_named_user_subject.txt', email_template_name='emails/deactivate/deactivate_named_user.txt', to_email=user.email, context={}, html_email_template_name='emails/deactivate/deactivate_named_user.html' ) track_sent_emails(user=user, alert_type='deactivation_email', emails=user.email)
def send_revoke_account_admin_notification(user): context = {'company': user.get_company()} send_mail( subject_template_name= 'emails/deactivate/revoke_access_admin_subject.txt', email_template_name='emails/deactivate/revoke_access_admin.txt', to_email=user.email, context=context, html_email_template_name='emails/deactivate/revoke_access_admin.html') track_sent_emails(user=user, alert_type='send_revoke_account_admin_notification', emails=user.email)
def send_activate_account_notification(user): context = {'company': user.company, 'user': user} send_mail( subject_template_name='emails/activate/activate_email_subject.txt', email_template_name='emails/activate/activate_email.txt', to_email=user.email, context=context, html_email_template_name='emails/activate/activate_email.html', bcc=settings.BCC) track_sent_emails(user=user, alert_type='send_activate_account_notification', emails=[user.email, settings.BCC])
def send_duplicate_account_notification(user): context = {'user': user} send_mail( subject_template_name='emails/duplicate/duplicate_email_subject.txt', email_template_name='emails/duplicate/duplicate_email.txt', to_email=user.email, context=context, html_email_template_name='emails/duplicate/duplicate_email.html', ) track_sent_emails(user=user, alert_type='send_duplicate_account_notification', emails=[user.email])
def send_account_admin_notification(user, invited_by): context = { 'name': user.first_name, 'company': user.get_company(), } send_mail(subject_template_name='emails/promotion/role_admin_subject.txt', email_template_name='emails/promotion/role_admin.txt', to_email=user.email, context=context, html_email_template_name='emails/promotion/role_admin.html') track_sent_emails(user=user, alert_type='send_account_admin_notification', emails=user.email)
def send_new_user_notification(user): site = Site.objects.get_current() context = {'site_name': site.name, 'user': user} send_mail(subject_template_name='emails/new_user/new_user_subject.txt', email_template_name='emails/new_user/new_user.txt', to_email=settings.USER_MANAGEMENT_EMAIL, context=context, html_email_template_name='emails/new_user/new_user.html', bcc=settings.BCC) track_sent_emails(user=user, alert_type='send_new_user_notification', emails=[settings.USER_MANAGEMENT_EMAIL, settings.BCC])
def send_new_partner_notification(partner, client, company_admin): company_members = partner.named_users.all().values_list('email', flat=True) to_emails = [c for c in company_members] context = {'company': client.name, 'company_admin': company_admin} send_mail( subject_template_name='emails/partnership/new_partnership_subject.txt', email_template_name='emails/partnership/new_partnership.txt', to_email=to_emails, context=context, html_email_template_name='emails/partnership/new_partnership.html') log_emails( u'Alert Sent: send_new_partner_notification, Recipient(s): {}, Added: {}' .format(to_emails, timezone.now()))
def send_notification_mail(obj=None, user=None, mail_message=""): if obj and user: mail_title = "Update do Mootiro Maps" if not mail_message: mail_message = """ Olá {}, O objeto "{}" que você está seguindo foi atualizado. Visite: {} para ver mais detalhes. atenciosamente, a equipe IT3S. """.format( user.name, unicode(obj), "http://maps.mootiro.org" + obj.view_url ) send_mail(mail_title, mail_message, "*****@*****.**", [user.email])
def send_activation_email(user, key): activation_link = '{}://{}{}'.format( settings.PROTOCOL, Site.objects.get_current().domain, reverse('profile:activate', kwargs={'activation_key': key})) context = {'activation_link': activation_link, 'name': user.first_name} send_mail(subject_template_name='emails/activate/verify_email_subject.txt', email_template_name='emails/activate/verify_email.txt', to_email=user.email, context=context, html_email_template_name='emails/activate/verify_email.html', bcc=settings.BCC) track_sent_emails(user=user, alert_type='activation_email', emails=[user.email, settings.BCC])
def send_invitation(invitation): existing = email_exists(invitation.email) if existing: invitation_link = '{}://{}{}?next={}'.format( settings.PROTOCOL, Site.objects.get_current().domain, reverse('social:begin', args=['gluu']), reverse('profile:accept-invite', kwargs={'activation_key': invitation.activation_key})) else: invitation_link = '{}://{}{}'.format( settings.PROTOCOL, Site.objects.get_current().domain, reverse('profile:register-named', kwargs={'activation_key': invitation.activation_key}), ) context = { 'name': invitation.invited_by.get_full_name(), 'invited_by': invitation.invited_by.get_full_name(), 'company': invitation.invited_by.company_association.name, 'invitation_link': invitation_link, 'existing': existing } try: account = UserProfile.objects.get(email=invitation.email) if (account.first_name != ""): context['fname'] = account.first_name except UserProfile.DoesNotExist: pass send_mail(subject_template_name='emails/invite/invite_named_subject.txt', email_template_name='emails/invite/invite_named.txt', to_email=invitation.email, context=context, html_email_template_name='emails/invite/invite_named.html', bcc=settings.BCC) log_emails( u'Alert Sent: send_invitation, Recipient(s): {}, Added: {}'.format( invitation.email, timezone.now()))
def send_notification_mail(obj=None, user=None, mail_message=''): if obj and user: mail_title = "Update do Mootiro Maps" if not mail_message: mail_message = """ Olá {}, O objeto "{}" que você está seguindo foi atualizado. Visite: {} para ver mais detalhes. atenciosamente, a equipe IT3S. """.format(user.name, unicode(obj), 'http://maps.mootiro.org' + obj.view_url) send_mail( mail_title, mail_message, '*****@*****.**', [user.email], )
def add_solution_comment(request, solution_id): solution = Solution.objects.get(id=int(solution_id)) task = Task.objects.get(solution=solution) if request.is_ajax() and 'refresh_captcha' in request.GET: return refresh_captcha() if request.user.is_authenticated(): form = SolutionCommentForm(initial={ 'author': request.user, 'solution': solution }) form.fields['author_name'].widget = forms.HiddenInput() else: form = SolutionCommentForm(initial={'solution': solution}) if request.method == 'POST': form = SolutionCommentForm(request.POST) if request.user.is_authenticated(): form.fields['author_name'].widget = forms.HiddenInput() if form.is_valid(): comment = form.save() message_subject = 'New comment has been added to your solution for task \"%s\"' \ % task.name message_body = "User %s has added a new comment to your solution." +\ "\nGo here and view it:\nwww.it-recipes.com%s" a = comment.author if comment.author else comment.author_name url_link = str(reverse('tasks.views.task', args=(task.id, ))) message_body = message_body % (a, url_link) send_mail(solution.author.email, message_subject, message_body) return redirect('task', task.id) return render(request, 'tasks/solutioncomment.html', { 'form': form, 'task_id': task.id, })
def edit_solution_comment(request, comment_id): if request.is_ajax() and 'refresh_captcha' in request.GET: return refresh_captcha() try: comment = SolutionComment.objects.get(id=int(comment_id)) task_id = comment.solution.task.id except SolutionComment.DoesNotExist: return redirect('task', task_id) form = SolutionCommentForm(instance=comment) if request.user.is_authenticated(): form.fields['author_name'].widget = forms.HiddenInput() if request.method == 'POST': form = SolutionCommentForm(request.POST, instance=comment) if request.user.is_authenticated(): form.fields['author_name'].widget = forms.HiddenInput() if form.is_valid(): comment = form.save() message_subject = 'Comment to your solution has been edited' message_body = "User %s has edited comment to your solution." +\ "\nGo here and view it:\nwww.it-recipes.com%s" a = comment.author if comment.author else comment.author_name url_link = str(reverse('tasks.views.task', args=(task.id, ))) message_body = message_body % (a, url_link) send_mail(comment.solution.author.email, message_subject, message_body) return redirect('task', task_id) return render(request, 'tasks/solutioncomment.html', { 'form': form, 'task_id': task_id, })
def task(request, task_id): context_dict = {} context_dict['tags'] = TaskTag.objects.all().order_by('name') context_dict['list'] = get_subjects_tree() try: task = Task.objects.get(pk=int(task_id)) except Task.DoesNotExist: return redirect('tasks', 'all', 0) if request.user.is_authenticated(): form = SolutionForm(initial={'author': request.user, 'task': task}) form.fields['author_name'].widget = forms.HiddenInput() else: form = SolutionForm(initial={'task': task}) if request.is_ajax() and 'refresh_captcha' in request.GET: return refresh_captcha() if request.method == 'POST': if 'delete_request' in request.POST: if request.POST['type'] == 'task': task.delete() return HttpResponse("") elif request.POST['type'] == 'solution': solution = Solution.objects.get( pk=int(request.POST['item_id'])) solution.delete() return HttpResponse("") elif request.POST['type'] == 'solution comment': comment = SolutionComment.objects.get( pk=int(request.POST['item_id'])) comment.delete() return HttpResponse("") elif 'vote_request' in request.POST: if request.POST['type'] == 'task': task = Task.objects.get(pk=int(request.POST['item_id'])) task.votes += int(request.POST['value']) task.save() return HttpResponse("") elif request.POST['type'] == 'solution': solution = Solution.objects.get( pk=int(request.POST['item_id'])) solution.votes += int(request.POST['value']) solution.save() return HttpResponse("") else: form = SolutionForm(request.POST) if form.is_valid(): solution = form.save() message_subject = 'New solution has been added for your task \"%s\"' \ % task.name message_body = "User %s has added a new solution to your task." +\ "\nGo here and view it:\nwww.it-recipes.com%s" a = solution.author if solution.author else solution.author_name message_body = message_body % (a, request.get_full_path()) send_mail(task.author.email, message_subject, message_body) return redirect('task', task.id) else: if request.user.is_authenticated(): form.fields['author_name'].widget = forms.HiddenInput() context_dict['form'] = form context_dict['task'] = task solutions = [] user_can_view_solutions = any([s.author == request.user \ for s in Solution.objects.filter(task=task)]) context_dict['user_can_view_solutions'] = user_can_view_solutions for s in Solution.objects.filter(task=task).order_by('-votes'): solutions.append({ 'solution': s, 'comments': SolutionComment.objects.filter(solution=s).order_by('-date') }) context_dict['solutions'] = solutions return render(request, 'tasks/task.html', context_dict)
def send_mail_async(title='', message='', sender='', receivers=[], html=False): send_mail(title=title, message=message, sender=sender, receivers=receivers, html=html)