Example #1
0
    def send_email_alert(to_address: str, username: str):
        """ Send an email to user to alert them they have a new message"""
        if not to_address:
            return False  # Many users will not have supplied email address so return

        # TODO these could be localised if needed, in the future
        html_template = get_template('message_alert_en.html')
        text_template = get_template('message_alert_en.txt')

        html_template = html_template.replace('[USERNAME]', username)
        html_template = html_template.replace('[PROFILE_LINK]',
                                              get_profile_url(username))

        text_template = text_template.replace('[USERNAME]', username)
        text_template = text_template.replace('[PROFILE_LINK]',
                                              get_profile_url(username))

        subject = 'You have a new message on the HOT Tasking Manager'
        SMTPService._send_mesage(to_address, subject, html_template,
                                 text_template)

        return True
    def send_welcome_message(user: User):
        """ Sends welcome message to all new users at Sign up"""
        text_template = get_template('welcome_message_en.txt')

        text_template = text_template.replace('[USERNAME]', user.username)
        text_template = text_template.replace('[PROFILE_LINK]', get_profile_url(user.username))

        welcome_message = Message()
        welcome_message.to_user_id = user.id
        welcome_message.subject = 'Welcome to the HOT Tasking Manager'
        welcome_message.message = text_template
        welcome_message.save()

        return welcome_message.id