示例#1
0
def send_registration_email(email):
    if settings.DISABLE_EMAILS:
        logger.warning('Emails disabled. Welcome email not sent.')
        return

    commonutils.send_multipart_email(
        'email/register', {
            'PROJECT_NAME': settings.PROJECT_NAME,
            'login_url': f"{settings.PROJECT_APP_HOST}/login",
        }, 'Welcome to Helium', [email], [settings.DEFAULT_FROM_EMAIL])
示例#2
0
def send_password_reset_email(email, temp_password):
    if settings.DISABLE_EMAILS:
        logger.warning(f'Emails disabled. Reset password: {temp_password}')
        return

    commonutils.send_multipart_email(
        'email/forgot', {
            'password': temp_password,
            'settings': f"{settings.PROJECT_APP_HOST}/settings",
            'support': f"{settings.PROJECT_APP_HOST}/support",
        }, 'Your Helium Password Has Been Reset', [email])
示例#3
0
def send_verification_email(email, username, verification_code):
    if settings.DISABLE_EMAILS:
        logger.warning('Emails disabled. Verification code: {}'.format(verification_code))
        return

    commonutils.send_multipart_email('email/verification',
                                     {
                                         'PROJECT_NAME': settings.PROJECT_NAME,
                                         'username': username,
                                         'verification_code': verification_code,
                                         'verify_url': "{}/verify".format(settings.PROJECT_APP_HOST),
                                     },
                                     'Verify Your Email Address with Helium', [email])
示例#4
0
def send_email_reminder(email, subject, reminder_id, calendar_item_id,
                        calendar_item_type):
    # The instance may no longer exist by the time this request is processed, in which case we can simply and safely
    # skip it
    try:
        reminder = Reminder.objects.get(pk=reminder_id)
    except Reminder.DoesNotExist:
        logger.info(f'Reminder {reminder_id} does not exist. Nothing to do.')

        return

    if settings.DISABLE_EMAILS:
        logger.warning(
            f'Emails disabled. Reminder {reminder.pk} not being sent.')
        return

    try:
        if calendar_item_type == enums.EVENT:
            calendar_item = Event.objects.get(pk=calendar_item_id)
        elif calendar_item_type == enums.HOMEWORK:
            calendar_item = Homework.objects.get(pk=calendar_item_id)
        else:
            logger.info(
                f'Nothing to do here, as a calendar_item_type of {calendar_item_type} does not exist.'
            )

            return
    except (Event.DoesNotExist, Homework.DoesNotExist):
        logger.info(
            f'calendar_item_id {calendar_item_id} does not exist. Nothing to do.'
        )

        return

    timezone.activate(pytz.timezone(reminder.user.settings.time_zone))

    start = timezone.localtime(calendar_item.start).strftime(
        settings.NORMALIZED_DATE_FORMAT if calendar_item.all_day else settings.
        NORMALIZED_DATE_TIME_FORMAT)
    end = timezone.localtime(calendar_item.end).strftime(
        settings.NORMALIZED_DATE_FORMAT if calendar_item.all_day else settings.
        NORMALIZED_DATE_TIME_FORMAT)
    normalized_datetime = f'{start} to {end}' if calendar_item.show_end_time else start

    normalized_materials = None
    if reminder.homework:
        normalized_materials = calendar_item.materials.values_list('title',
                                                                   flat=True)
        normalized_materials = ', '.join(normalized_materials)

    comments = calendar_item.comments if calendar_item.comments.strip(
    ) != '' else None

    commonutils.send_multipart_email(
        'email/reminder', {
            'PROJECT_NAME': settings.PROJECT_NAME,
            'reminder': reminder,
            'calendar_item': calendar_item,
            'normalized_datetime': normalized_datetime,
            'normalized_materials': normalized_materials,
            'comments': comments,
        }, subject, [email])

    metricutils.increment('action.reminder.sent.email')

    timezone.deactivate()