def send_new_ticket_reminder(ticket, support_plan, notify_email=False): context = { 'ticket': ticket, 'ticket_link': generate_ticket_url(ticket), 'support_plan': support_plan } log_message = 'New Ticket Reminder to Staff Sent, Ticket: {}, Support Plan: {}, Issue Type: {}, Time passed: {}' log_emails(log_message.format( ticket.id, support_plan, ticket.issue_type, timezone.now() - ticket.last_updated_at )) if notify_email: send_email( subject_template_name='emails/reminders/new_ticket_reminder_subject.txt', email_template_name='emails/reminders/new_ticket_reminder.txt', to_email=settings.RECIPIENT_NEW_NOTIFICATIONS, context=context, html_email_template_name='emails/reminders/new_ticket_reminder.html', bcc=settings.DEFAULT_RECIPIENT_IDLE_TICKET_REMINDERS ) ticket.last_notification_sent = timezone.now() ticket.save()
def post(self, request, format=None): data = request.POST params_dict = { "razorpay_order_id": data.get("razorpay_order_id"), "razorpay_payment_id": data.get("razorpay_payment_id"), "razorpay_signature": data.get("razorpay_signature") } try: client.utility.verify_payment_signature(params_dict) except Exception: return Response(status = status.HTTP_400_BAD_REQUEST) details = client.order.fetch(data.get("razorpay_order_id")) donation = Donation() donation.donor = Donor.objects.get(user=request.user) donation.recipient = Recipient.objects.get(pk=details['notes']['recipient_id']) donation.amount = details['amount'] donation.razorpay_order_id = data.get("razorpay_order_id") donation.razorpay_payment_id = data.get("razorpay_payment_id") donation.razorpay_signature = data.get("razorpay_signature") donation.key = details['receipt'].split("#")[0] donation.save() message = 'Payment accepted. Unique ID - ' + str(donation.key) send_email(user.get_full_name(),user.email,message) return Response({"key":donation.key},status=status.HTTP_200_OK)
def send_idle_ticket_reminder_user(ticket, notify_email=False): context = { 'ticket': ticket, 'ticket_link': generate_ticket_url(ticket), 'time_passed': format_timedelta(timezone.now() - ticket.date_modified), 'unsubscribe_link': generate_unubscribe_link(ticket), 'close_ticket_link': '{}{}'.format(get_base_url(), reverse('close_ticket', kwargs={'id': ticket.id})) } log_message = u'Idle Ticket Reminder to User Sent, Ticket: {}, Recipient: {}, Time passed: {}' log_emails(log_message.format(ticket.id, ticket.owned_by, timezone.now() - ticket.last_updated_at)) if notify_email: send_email( subject_template_name='emails/reminders/idle_ticket_reminder_user_subject.txt', email_template_name='emails/reminders/idle_ticket_reminder_user.txt', to_email=ticket.owned_by.email, context=context, html_email_template_name='emails/reminders/idle_ticket_reminder_user.html', bcc=settings.DEFAULT_RECIPIENT_IDLE_TICKET_REMINDERS ) ticket.last_notification_sent = timezone.now() ticket.save()
def send_email_admin(): """ Sends an email to admin whenever someone submits a new implementation. """ message = "There is a new paper submission waiting to be approved." send_email(message, ADMIN_EMAIL, message)
def order_email(request, email, order_id): order = Order.objects.get(pk=order_id) order_details = [] grand_quantity_total = 0 grand_total = 0 for order_detail in order.order_details.all(): grand_quantity_total += order_detail.quantity grand_total += (order_detail.quantity * order_detail.price) order_details.append({ "pk": order_detail.pk, "quantity": order_detail.quantity, "style": order_detail.style, "size": order_detail.size, "description": order_detail.description, "sku": order_detail.sku, "price": order_detail.price, "total": order_detail.quantity * order_detail.price, }) data_object = { "image_path": settings.EMAIL_STATIC_URL, "order": order, "order_details": order_details, "grand_total": grand_total, "grand_quantity_total": grand_quantity_total, } email_subject = "Cobian Order" email_body = make_html_email('emails/order_email', data_object, context_instance=RequestContext(request)) return send_email(email_subject, email_body, email)
def notify_tagged_staff_member(answer, tag_user): ticket = answer.ticket encoded= base64.b32encode(str(ticket.id)) context = gather_answer_email_context(answer) send_email( subject_template_name='emails/new_answer/new_answer_tagged_staff_member_subject.txt', email_template_name='emails/new_answer/new_answer_tagged_staff_member.txt', to_email=To email will go here, context=context, html_email_template_name='emails/new_answer/new_answer_tagged_staff_member.html', from_email = "From Title <"+encoded+ "@your domain on mailgun>" ) track_sent_emails( ticket=ticket, emails=tag_user.email, alert_type=NEW_ANSWER_TAGGED_STAFF_MEMBER )
def send_pre_authorized_email(request, warranty): user_profile = request.user.userprofile email = user_profile.user.email emails = [email, warranty.email] email_subject = "Cobian Warranty Claim" email_body = make_html_email('emails/warranty_pre_authorized', {"warranty": warranty}, context_instance=RequestContext(request)) return send_email(email_subject, email_body, emails)
def notify_ticket_assigned(ticket, user): context = gather_ticket_email_context(ticket) encoded= base64.b32encode(str(ticket.id)) context['ticket_assigned_by'] = user context['ticket_assigned_to'] = ticket.assigned_to context['first_name']=ticket.assigned_to.get_short_name if ticket.assigned_to != user: send_email( subject_template_name='emails/ticket_assigned/ticket_assigned_subject.txt', email_template_name='emails/ticket_assigned/ticket_assigned.txt', to_email=ticket.assigned_to.email, from_email = "From Title <"+encoded+ "@your domain on mailgun>", context=context, html_email_template_name='emails/ticket_assigned/ticket_assigned.html' ) track_sent_emails( ticket=ticket, emails=ticket.assigned_to.email, alert_type=TICKET_ASSIGNED ) if ticket.assigned_first_time and ticket.owned_by != user and ticket.created_by.is_named: send_email( subject_template_name='emails/ticket_assigned/ticket_assigned_to_creator_subject.txt', email_template_name='emails/ticket_assigned/ticket_assigned_to_creator.txt', to_email=ticket.owned_by.email, from_email = "From Title <"+encoded+ "@your domain on mailgun>", context=context, html_email_template_name='emails/ticket_assigned/ticket_assigned_to_creator.html' ) track_sent_emails( ticket=ticket, emails=ticket.owned_by.email, alert_type=TICKET_ASSIGNED_OWNER )
def register_view(request): if request.user.is_authenticated: return redirect(reverse('index')) next = request.GET.get('next') form = UserRegisterForm(request.POST or None) if form.is_valid(): username = form.cleaned_data.get("username") password = form.cleaned_data.get("password") email = form.cleaned_data.get("email") user = form.save(commit=False) user.set_password(password) user.save() subject = "Thank you for registering to NISQ Algorithm Zoo" message = "You can now login as {} and submit new NISQ algorithm implementations.".format( username) send_email(subject, email, message) new_user = authenticate(username=username, password=password) if new_user: login(request, new_user) if next: return redirect(next) else: return redirect(reverse('index')) context = { 'form': form, } return render(request, 'accounts/register.html', context=context)
def notify_ticket_reopened(ticket, user): context = gather_ticket_email_context(ticket) context['ticket_reopened_by'] = user context['ticket_reopened_by_comp']=user.get_company() to_emails = test_emails.append(settings.RECIPIENT_NEW_NOTIFICATIONS) if ticket.assigned_to and ticket.assigned_to != user: to_emails.append(ticket.assigned_to.email) send_email( subject_template_name='emails/new_ticket/ticket_reopened_subject.txt', email_template_name='emails/new_ticket/ticket_reopened.txt', to_email=to_emails, context=context, html_email_template_name='emails/new_ticket/ticket_reopened.html', ) track_sent_emails( ticket=ticket, emails=to_emails, alert_type=TICKET_REOPENED )
def send_new_ticket_reminder_basic(ticket, notify_email=False): context = { 'ticket': ticket, 'ticket_link': generate_ticket_url(ticket) } log_message = 'New Ticket Reminder for community user to Staff Sent, Ticket: {}, Time passed: {}' log_emails(log_message.format(ticket.id, timezone.now() - ticket.last_updated_at)) if notify_email: send_email( subject_template_name='emails/reminders/new_ticket_reminder_basic_subject.txt', email_template_name='emails/reminders/new_ticket_reminder_basic.txt', to_email=settings.RECIPIENT_NEW_NOTIFICATIONS, context=context, html_email_template_name='emails/reminders/new_ticket_reminder_basic.html', bcc=settings.DEFAULT_RECIPIENT_IDLE_TICKET_REMINDERS ) ticket.last_notification_sent = timezone.now() ticket.save()
def post(self, request, format=None): data = request.POST donor_id = data.get("donor_id") try: donor = Donor.objects.get(pk = donor_id) except ObjectDoesNotExist: return Response(status=status.HTTP_400_BAD_REQUEST) if donor is not None: donor_name = donor.user.get_full_name() donor_email = donor.email message = 'Dear ' + str(donor_name) + ', \nThanks a lot for your kindness. Your Donation means a lot to us. I promise to return back the amount to you in goods' email_fun_response = send_email(donor_name, donor_email,message) if email_fun_response: return Response(status=status.HTTP_200_OK) else: return Response(status=status.HTTP_400_BAD_REQUEST) else: return Response(status=status.HTTP_400_BAD_REQUEST)
def notify_new_answer(answer, send_copy=False): ticket = answer.ticket encoded= base64.b32encode(str(ticket.id)) context = gather_answer_email_context(answer) to_emails = [] if answer.created_by != ticket.owned_by and ticket.owned_by.is_active: to_emails.append(ticket.owned_by.email) if (ticket.assigned_to and answer.created_by != ticket.assigned_to and ticket.assigned_to.is_active): to_emails.append(ticket.assigned_to.email) if to_emails: send_email( subject_template_name='emails/new_answer/new_answer_subject.txt', email_template_name='emails/new_answer/new_answer.txt', to_email=to_emails, from_email = "From Title <"+encoded+ "@your domain on mailgun>", context=context, html_email_template_name='emails/new_answer/new_answer.html', ) track_sent_emails( ticket=ticket, emails=to_emails, alert_type=NEW_ANSWER ) excluded_subscribers = [answer.created_by.email, ticket.owned_by.email] if ticket.assigned_to: excluded_subscribers.append(ticket.assigned_to.email) ticket_alerts = TicketAlerts.objects.filter( ticket=answer.ticket, user__is_active=True).exclude( user__email__in=excluded_subscribers ) to_emails = [alert.user.email for alert in ticket_alerts] to_emails = list(set(to_emails)) if ticket.company_association: company = ticket.company_association subscribed_company_members = company.named_users.filter( is_active=True, receive_all_notifications=True).exclude( email__in=excluded_subscribers) subscribed_company_members = [user.email for user in subscribed_company_members] to_emails = list(set(to_emails) | set(subscribed_company_members)) if to_emails: send_email( subject_template_name='emails/new_answer/new_answer_subject.txt', email_template_name='emails/new_answer/new_answer_subscriber.txt', to_email=to_emails, from_email = "From Title <"+encoded+ "@your domain on mailgun>", context=context, html_email_template_name='emails/new_answer/new_answer_subscriber.html', ) track_sent_emails( ticket=ticket, emails=to_emails, alert_type=NEW_ANSWER_SUBSCRIBERS ) if send_copy: to_emails = [e.strip() for e in answer.send_copy.split(',')] send_email( subject_template_name='emails/new_answer/new_answer_copy_subject.txt', email_template_name='emails/new_answer/new_answer_copy.txt', to_email=to_emails, context=context, html_email_template_name='emails/new_answer/new_answer_copy.html', from_email = "From Title <"+encoded+ "@your domain on mailgun>" ) track_sent_emails( ticket=ticket, emails=to_emails, alert_type=NEW_ANSWER_COPY )
def notify_new_ticket(ticket, send_copy=False): context = gather_ticket_email_context(ticket) encoded= base64.b32encode(str(ticket.id)) # test_emails.append(settings.RECIPIENT_NEW_NOTIFICATIONS) if ticket.created_for: send_email( subject_template_name='emails/new_ticket/new_ticket_subject.txt', email_template_name='emails/new_ticket/new_ticket_for_user.txt', to_email=ticket.created_for.email, context=context, from_email = "From Title <"+encoded+ "@your domain on mailgun>" , html_email_template_name='emails/new_ticket/new_ticket_for_user.html' ) send_email( subject_template_name='emails/new_ticket/new_ticket_subject.txt', email_template_name='emails/new_ticket/new_ticket_for_staff.txt', to_email=test_emails, context=context, from_email = "From Title <"+encoded+ "@your domain on mailgun>" , html_email_template_name='emails/new_ticket/new_ticket_for_staff.html' ) track_sent_emails( ticket=ticket, alert_type=NEW_TICKET_FOR_USER, emails=[ticket.created_for.email, test_emails] ) if ticket.created_for.is_named: if ticket.created_by.get_company() == 'Gluu': company_members_creator = [] else: company_members_creator = ticket.created_by.company_association.named_users.filter(is_active=True, receive_all_notifications=True).exclude( email=ticket.created_by.email).values_list('email', 'first_name') all_mambers = [] for member in company_members_creator: all_mambers.append([member[0], member[1]]) company_members_owner = ticket.created_for.company_association.named_users.filter(is_active=True, receive_all_notifications=True).exclude( email=ticket.created_for.email).values_list('email', 'first_name') for member in company_members_owner: all_mambers.append([member[0], member[1]]) if all_mambers: for item in all_mambers: context['named_user_name'] = item[1] send_email( subject_template_name='emails/new_ticket/new_ticket_subject.txt', email_template_name='emails/new_ticket/new_ticket_for_named.txt', to_email=item[0], from_email = "From Title <"+encoded+ "@your domain on mailgun>", context=context, html_email_template_name='emails/new_ticket/new_ticket_for_named.html' ) track_sent_emails( ticket=ticket, emails=item[0], alert_type=NEW_TICKET_FOR_NAMED ) else: if ticket.created_by.is_admin: send_email( subject_template_name='emails/new_ticket/new_ticket_subject.txt', email_template_name='emails/new_ticket/new_ticket_by_staff.txt', to_email=test_emails, context=context, from_email = "From Title <"+encoded+ "@your domain on mailgun>" , html_email_template_name='emails/new_ticket/new_ticket_by_staff.html' ) track_sent_emails( ticket=ticket, alert_type=NEW_TICKET_BY_STAFF, emails=[test_emails] ) if ticket.created_by.is_basic: send_email( subject_template_name='emails/new_ticket/new_ticket_subject.txt', email_template_name='emails/new_ticket/new_ticket.txt', to_email='To email will go here', from_email = "From Title <"+encoded+ "@your domain on mailgun>", context=context, html_email_template_name='emails/new_ticket/new_ticket.html' ) track_sent_emails( ticket=ticket, alert_type=NEW_TICKET, emails=test_emails ) elif ticket.created_by.is_named: company = ticket.created_by.company_association context['ticket_created_by_comp'] = ticket.created_by.company_association.name send_email( subject_template_name='emails/new_ticket/new_ticket_subject.txt', email_template_name='emails/new_ticket/new_ticket_by_named.txt', to_email=test_emails, from_email = "From Title <"+encoded+ "@your domain on mailgun>", context=context, html_email_template_name='emails/new_ticket/new_ticket_by_named.html' ) track_sent_emails( ticket=ticket, emails=test_emails, alert_type=NEW_TICKET_BY_NAMED ) company_members = company.named_users.filter(is_active=True, receive_all_notifications=True).exclude( email=ticket.created_by.email).values_list('email', 'first_name') if company_members: for item in company_members: context['named_user_name'] = item[1] send_email( subject_template_name='emails/new_ticket/new_ticket_subject.txt', email_template_name='emails/new_ticket/new_ticket_for_named.txt', from_email = "From Title <"+encoded+ "@your domain on mailgun>", to_email=item[0], context=context, html_email_template_name='emails/new_ticket/new_ticket_for_named.html' ) track_sent_emails( ticket=ticket, emails=item[0], alert_type=NEW_TICKET_BY_NAMED ) if send_copy: to_emails = [e.strip() for e in ticket.send_copy.split(',')] send_email( subject_template_name='emails/new_ticket/new_ticket_copy_subject.txt', email_template_name='emails/new_ticket/new_ticket_copy.txt', to_email=to_emails, context=context, html_email_template_name='emails/new_ticket/new_ticket_copy.html', from_email = "From Title <"+encoded+ "@your domain on mailgun>" ) track_sent_emails( ticket=ticket, emails=test_emails, alert_type=NEW_TICKET_COPY )