def send_requirements_email(person): from_person = get_person_by_position('Secretary') if from_person is None: signature = 'Crimson Key Society' else: signature = from_person.first_name from_email = get_email_by_position('Secretary') to_emails = ['{} <{}>'.format(person.full_name, person.email)] subject = 'Crimson Key Requirements Update' dues_status = person.dues_status() person.cached_status = { 'tours_status': person.tours_status(), 'shifts_status': person.shifts_status(), 'dues_status': dues_status, } collect_dues = dues_required() context = { 'person': person, 'collect_dues': collect_dues, 'dues_required': dues_required, 'signature': signature } send_email(subject, to_emails, from_email, 'email/requirements_email.txt', 'email/requirements_email.html', context)
def email_notification(version, build, email): log.debug( LOG_TEMPLATE.format(project=version.project.slug, version=version.slug, msg='sending email to: %s' % email)) context = { 'version': version, 'project': version.project, 'build': build, 'build_url': 'https://{0}{1}'.format( getattr(settings, 'PRODUCTION_DOMAIN', 'readthedocs.org'), build.get_absolute_url()), 'unsub_url': 'https://{0}{1}'.format( getattr(settings, 'PRODUCTION_DOMAIN', 'readthedocs.org'), reverse('projects_notifications', args=[version.project.slug])), } if build.commit: title = _('Failed: {project.name} ({commit})').format( commit=build.commit[:8], **context) else: title = _('Failed: {project.name} ({version.verbose_name})').format( **context) send_email(email, title, template='projects/email/build_failed.txt', template_html='projects/email/build_failed.html', context=context)
def email_notification(version, build, email): log.debug( LOG_TEMPLATE.format(project=version.project.slug, version=version.slug, msg="sending email to: %s" % email) ) context = { "version": version, "project": version.project, "build": build, "build_url": "https://{0}{1}".format( getattr(settings, "PRODUCTION_DOMAIN", "readthedocs.org"), build.get_absolute_url() ), "unsub_url": "https://{0}{1}".format( getattr(settings, "PRODUCTION_DOMAIN", "readthedocs.org"), reverse("projects_notifications", args=[version.project.slug]), ), } if build.commit: title = _("Failed: {project.name} ({commit})").format(commit=build.commit[:8], **context) else: title = _("Failed: {project.name} ({version.verbose_name})").format(**context) send_email( email, title, template="projects/email/build_failed.txt", template_html="projects/email/build_failed.html", context=context, )
def new(request, lang): if request.method == 'POST': participant_form = ParticipantForm(request.POST) if participant_form.is_valid(): participant = participant_form.save(commit=False) participant.ip = get_client_ip(request), participant.ua = get_client_ua(request), participant.save() sequences = Sequence.objects.all() pairs = Pair.objects.all() if len(sequences) > len(pairs): generate_pairs(len(sequences) - len(pairs) + 1) pairs = Pair.objects.all() send_email(template='email/pairs_empty.html') pairs = pairs[:len(sequences)] for sequence, pair in zip(sequences, pairs): question = Question(participant=participant, left=pair.left, right=pair.right, sequence=sequence, answered=False) question.save() pair.delete() request.session['participant_id'] = participant.id #messages.add_message(request, messages.SUCCESS, u'Новый участник создан') return redirect(reverse('core.views.index', kwargs={'lang': lang})) #messages.add_message(request, messages.ERROR, u'Не удалось создать участника') return redirect(reverse('core.views.index', kwargs={'lang': lang}))
def send_verification(self): SITE_URL = get_site_url() code, message = None, None if self.user: subject = "Verify Email" message_html = "email/verify_email.html" email_from = "" email_to = [self.user.email] token = default_token_generator.make_token(self.user) uidb64 = urlsafe_base64_encode(force_bytes(self.user.pk)) obj_model = { 'phone_number': self.user.phone_number, 'first_name': self.user.first_name, 'verify_email_url': SITE_URL + reverse('verifyemail', kwargs={ 'uidb64': str(uidb64, 'utf-8'), 'token': token }) } print('verify_email_url', obj_model['verify_email_url']) send_email(subject, message_html, email_from, email_to, obj_model) return True return False
def email_notification(version, build, email): log.debug(LOG_TEMPLATE.format(project=version.project.slug, version=version.slug, msg='sending email to: %s' % email)) context = {'version': version, 'project': version.project, 'build': build, 'build_url': 'https://{0}{1}'.format( getattr(settings, 'PRODUCTION_DOMAIN', 'readthedocs.org'), build.get_absolute_url()), 'unsub_url': 'https://{0}{1}'.format( getattr(settings, 'PRODUCTION_DOMAIN', 'readthedocs.org'), reverse('projects_notifications', args=[version.project.slug])), } if build.commit: title = _('Failed: {project.name} ({commit})').format(commit=build.commit[:8], **context) else: title = _('Failed: {project.name} ({version.verbose_name})').format(**context) send_email( email, title, template='projects/email/build_failed.txt', template_html='projects/email/build_failed.html', context=context )
def send_order_through_email_action(self, request, queryset): """ Custom action to send orders as csv through email. """ try: opts = queryset.model._meta csv_str = StringIO.StringIO() writer = csv.writer(csv_str) field_names = [field.name for field in opts.fields] # Header row writer.writerow(field_names) # Data rows for obj in queryset: writer.writerow([ unicode(getattr(obj, field)).encode("utf-8") for field in field_names ]) # the wonderful world of encoding send_email(csv_str) self.message_user(request, 'Email enviado correctamente', level=messages.SUCCESS) except Exception: self.message_user(request, 'Error al enviar los mails', level=messages.ERROR)
def create_and_send_validation_email(user, request): token = EmailValidationToken(user=user) token.save() send_email( 'email/user_register.html', user.email, url_validation=token.generate_validation_url(request))
def send_notification(request): try: send_email(request.data["email"]) except Exception as e: trace_back = traceback.format_exc() message = str(e) + " " + str(trace_back) print(message) return Response({"message": message}, status=status.HTTP_500_INTERNAL_SERVER_ERROR) return Response({"message": "Email has been sent"})
def lambda_handler(event, context): """ This is the function AWS Lambda will call when running the application. """ email_body = render_template(simfonia, diverso, actiunia, obligatiuni, total, Graph.PLOT_MAX_PIXELS) send_email(Email.SUBJECT, email_body, Email.AWS_REGION, Email.RECIPIENT, Email.CHARSET, Email.SENDER) return {'statusCode': 200}
def send_email_verification(user): uid = urlsafe_base64_encode(force_bytes(user.pk)) token = activation_token_generator.make_token(user) context = {'link': full_reverse('activate', args=[uid, token])} send_email(subject="Verify your RosterSniper account", to=[user.email], file='verification', context=context)
def send_tour_reminder_email(tour): from_email = get_email_by_position('Tour Coordinator (Primary)', 'Tour Coordinator') to_person = tour.guide to_emails = ['{} <{}>'.format(to_person.full_name, to_person.email)] subject = 'Tour Tomorrow at {}'.format(tour.time_local().strftime('%-I:%M %p')) allow_texting = core_utils.get_setting('Allow Texting to Info Center') info_center_name = core_utils.get_setting('Info Center Director Name') info_center_phone = core_utils.get_setting('Info Center Phone Number') context = {'tour': tour, 'allow_texting': allow_texting, 'info_center_name': info_center_name, 'info_center_phone': info_center_phone} core_utils.send_email(subject, to_emails, from_email, 'email/tour_reminder.txt', 'email/tour_reminder.html', context)
def forgotpassword(request): """ forgot password """ print('forgotpassword', settings.EMAIL_HOST_PASSWORD, settings.EMAIL_HOST_USER) SITE_URL = get_site_url() email_address = request.data.get('email') code, message = None, None if not email_address: code = ValidationStatusCode.EMAIL_ADDRESS_IS_EMPTY.value message = VALIDATION_CODE[ValidationStatusCode.EMAIL_ADDRESS_IS_EMPTY] elif email_address and not is_email(email_address): code = ValidationStatusCode.EMAIL_ADDRESS_IS_INVALID.value message = VALIDATION_CODE[ ValidationStatusCode.EMAIL_ADDRESS_IS_INVALID] else: if User.objects.filter(email=email_address).exists(): user = User.objects.get(email=email_address) subject = "Password Reset" message_html = "email/reset_password.html" email_from = "" email_to = [user.email] token = default_token_generator.make_token(user) uidb64 = urlsafe_base64_encode(force_bytes(user.pk)) obj_model = { 'phone_number': user.phone_number, 'full_name': user.full_name, 'reset_pass_url': SITE_URL + reverse('resetpassword', kwargs={ 'uidb64': str(uidb64, 'utf-8'), 'token': token }) } print('reset_pass_url', obj_model['reset_pass_url']) send_email(subject, message_html, email_from, email_to, obj_model) code = 200 message = _('Please check your email to get the new password!') else: code = ValidationStatusCode.EMAIL_ADDRESS_IS_INVALID.value message = VALIDATION_CODE[ ValidationStatusCode.EMAIL_ADDRESS_IS_INVALID] return HttpResponse(json.dumps({ 'code': code, 'message': message }), content_type='application/json', status=200)
def run(self): try: request = self.request # Send New Request Information subject = "Yatra Ninja : New Request " + str( request.id) + " Posted" mail_content = generate_html_from_json( request.get_request_details()) request_context = {} request_context['mail_content'] = mail_content message = get_template('request.html').render(request_context) send_email(subject, None, message) except: pass
def set_enrollment(self, enrolled, capacity): available = capacity - enrolled favorites = self.favorite_set.filter(email_notify=True, user__email_confirmed=True, user__email_notify=True) # If there's a new opening or new closing # # We make sure favorites is non-empty first because if it's empty, the # section might not exist in the DB, and self.available might be None, # and None <= 0 causes an error. if favorites and ((self.available <= 0 and available > 0) or (self.available > 0 and available <= 0)): # Most of these could be calculated in the template but because # there are two templates it is done here so it doesn't need to be # done twice. # # Also, the 'status' condition might look unintuitive but basically # closed originally + notification = seat available now # (self.available is updated after this method is called) context = { 'status': 'opened!' if self.available <= 0 else 'closed.', 'section_title': self.section_title, 'professor': self.get_prof_name(), 'crn': self.crn } for favorite in favorites: context['unsub_fav'] = full_reverse( 'unsubscribe', args=['favorite', favorite.email_unsub_id]) context['unsub_all'] = full_reverse( 'unsubscribe', args=['all', favorite.user.email_unsub_id]) send_email( subject= f"{context['section_title']} just {context['status']}", to=[favorite.user.email], file='favorite', context=context) # This condition is more general than the one above if self.available != available: self.enrolled = enrolled self.available = available self.capacity = capacity
def send_shift_reminder_email(shift): source_to_positions = { "TEACH": ('Tour Coordinator', 'Tour Coordinator (Primary)', 'Freshman Week Coordinator'), "Parents' Weekend": ('Freshman Week Coordinator',), "Visitas": ('Freshman Week Coordinator',), "Comp": ('Vice President',), "Arts First": ('Freshman Week Coordinator',), "Freshman Week": ('Freshman Week Coordinator',), "Other": ('Freshman Week Coordinator',), } from_email = get_email_by_position(*source_to_positions.get(shift.source)) to_person = shift.person to_emails = ['{} <{}>'.format(to_person.full_name, to_person.email)] subject = 'Shift Tomorrow at {}'.format(shift.time_local().strftime('%-I:%M %p')) context = {'shift': shift} send_email(subject, to_emails, from_email, 'email/shift_reminder.txt', 'email/shift_reminder.html', context)
def send_requirements_email(person): from_person = get_person_by_position('Secretary') if from_person is None: signature = 'Crimson Key Society' else: signature = from_person.first_name from_email = get_email_by_position('Secretary') to_emails = ['{} <{}>'.format(person.full_name, person.email)] subject = 'Crimson Key Requirements Update' dues_status = person.dues_status() person.cached_status = { 'tours_status': person.tours_status(), 'shifts_status': person.shifts_status(), 'dues_status': dues_status, } collect_dues = dues_required() context = {'person': person, 'collect_dues': collect_dues, 'dues_required': dues_required, 'signature': signature} send_email(subject, to_emails, from_email, 'email/requirements_email.txt', 'email/requirements_email.html', context)
def new(request, lang): if request.method == 'POST': participant_form = ParticipantForm(request.POST) if participant_form.is_valid(): participant = participant_form.save(commit=False) participant.ip = get_client_ip(request), participant.ua = get_client_ua(request), participant.save() sequences = Sequence.objects.all() pairs = Pair.objects.all() if len(sequences) > len(pairs): generate_pairs(len(sequences) - len(pairs) + 1) pairs = Pair.objects.all() send_email(template='email/pairs_empty.html') pairs = pairs[:len(sequences)] for sequence, pair in zip(sequences, pairs): question = Question( participant=participant, left=pair.left, right=pair.right, sequence=sequence, answered=False ) question.save() pair.delete() request.session['participant_id'] = participant.id #messages.add_message(request, messages.SUCCESS, u'Новый участник создан') return redirect(reverse('core.views.index', kwargs={'lang': lang})) #messages.add_message(request, messages.ERROR, u'Не удалось создать участника') return redirect(reverse('core.views.index', kwargs={'lang': lang}))
def delete_section(sender, instance, **kwargs): """ Sends an email to all watchers when a section is deleted e.g. when the section is no longer present in banner and the command update section --remove-old is ran. Because deleting a section automatically deletes all associated favorites I thought about making sender=Favorite but then it would trigger when a user unfavorites a section which is not what we want. """ section = instance favorites = section.favorite_set.filter( user__email_confirmed=True, user__email_notify=True) if not favorites: return # Most of these could be calculated in the template but because there are # two templates it is done here so it doesn't need to be done twice. context = { 'section_title': section.section_title, 'professor': section.get_prof_name(), 'crn': section.crn } for favorite in favorites: context['unsub_all'] = full_reverse( 'unsubscribe', args=['all', favorite.user.email_unsub_id]) send_email( subject=f"{context['section_title']} has been deleted", to=[favorite.user.email], file='deleted_section', context=context )
def handle(self, *args, **options): log.debug("Sending email") cart = Cart.objects.first() if cart.updated: send_email(ADMIN_ACCOUNT["email"])