Skip to content
Snippets Groups Projects
Forked from infrastruktur / warpinfra
61 commits behind the upstream repository.
util.py 1.05 KiB
from django.core.mail import send_mail
from django.conf import settings
from django.utils.translation import ugettext as _
from matterhook import Webhook
import logging

page_context = {'pages': [
    {"link": "pizza", "name": _("pizza_sheet")},
    {"link": "about", "name": _("about")},
], 'debug': settings.DEBUG}



def send_to_mattermost(username, channel, message):
    try:
        if settings.API_KEY:
            hook = Webhook("https://mattermost.warpzone.ms", settings.API_KEY)
            if settings.DEBUG:
                username = "["+channel+"] "+username
                channel = "warpinfradebug"
            hook.send(message, channel=channel, username=username)
    except Exception as e:
        logging.getLogger("django").error(e)

def send_email(to_address, subject, content):
    try:
        send_mail(
            '[WarpInfra] %s' % subject,
            content,
            settings.EMAIL_FROM,
            [to_address],
            fail_silently=False,
        )
        return True
    except Exception as e:
        print(e)
    
    return False