def init_email_error_handler(app):
    """
    Initialize a logger to send emails on error-level messages.
    Unhandled exceptions will now send an email message to app.config.ADMINS.
    """
    if app.debug:
        return
    host = app.config['MAIL_SERVER']
    port = app.config['MAIL_PORT']
    from_addr = app.config['MAIL_DEFAULT_SENDER']
    secure = () if app.config.get('MAIL_USE_TLS') else None
    to_addr_list = app.config['ADMINS']
    subject = app.config.get('APP_SYSTEM_ERROR_SUBJECT_LINE', 'System Error')
    import logging
    from logging.handlers import SMTPHandler
    mail_handler = SMTPHandler(mailhost=(host, port), fromaddr=from_addr,
        toaddrs=to_addr_list, subject=subject, credentials=None, secure=secure)
    mail_handler.setLevel(logging.ERROR)
    app.logger.addHandler(mail_handler)
