Django, custom SMTP server for logging only

One of my client uses google apps, so I use that account to send out mails with Django, which works just fine. However, google silently drops all error mails to the admins, for whatever reason you can't debug and will never hear anything about anyway. As those mails only go to the dev team it doesn't really matter which mailserver is used, so I decided to write my own email handler. To use it add it to the LOGGING settings like you would the normal AdminEmailHandler and add the necessary settings to your configuration.

Raw
from django.conf import settings
from django.core.mail import get_connection
from django.utils.log import AdminEmailHandler


class MyAdminEmailHandler(AdminEmailHandler):
    """
    Use a custom handler because gmail sucks...
    """
    def connection(self):
        return get_connection(
            host=settings.LOG_EMAIL_HOST,
            port=settings.LOG_EMAIL_PORT,
            username=settings.LOG_EMAIL_USER,
            password=settings.LOG_EMAIL_PASSWORD,
            use_tls=settings.LOG_EMAIL_USE_TLS,
        )

0 comments

Reply

Cancel reply
Markdown. Syntax highlighting with <code lang="php"><?php echo "Hello, world!"; ?></code> etc.
DjangoPythonBitcoinTuxDebianHTML5 badgeSaltStackUpset confused bugMoneyHackerUpset confused bugX.OrggitFirefoxWindowMakerBashIs it worth the time?i3 window managerWagtailContainerIrssiNginxSilenceUse a maskWorldInternet securityPianoFontGnuPGThunderbirdJenkinshome-assistant-logo