abhishek-ram/django-pyas2

Email event notifications.

zalejus opened this issue · 1 comments

Hi everybody,
it's more a question not an issue. Please, tell me how to configure mail notifications in django-pyas2 if messege's STATUS is changed to ERROR. I've already tried to set EMAIL_HOST, etc. in my settings.py, but it doesn't work in this version. I found that in pyas2 was a bit of code which done this job, but here I'm afraid it disappeared.
Below the code from pyas2 about an email (maybe I'm wrong...)

        # Build and send the AS2 message
        try:
            payload = as2lib.build_message(message)
            as2lib.send_message(message, payload)	
        except Exception:
            message.status = 'E'
            txt = traceback.format_exc(None).decode('utf-8', 'ignore')
            message.adv_status = \
                _(u'Failed to send message, error:\n%(txt)s') % {'txt': txt}
            pyas2init.logger.error(message.adv_status)

            models.Log.objects.create(
                message=message, status='E', text=message.adv_status)
            message.save()

            # Send mail here
            as2utils.senderrorreport(message, message.adv_status)
            sys.exit(2)

You may use default Django Logging as well if you want to use system mail managers - maybe something like this ?


LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'formatters': {
        'verbose': {
            'format': '{levelname} {asctime} {module} {process:d} {thread:d} {message}',
            'style': '{',
        },
        'simple': {
            'format': '{levelname} {message}',
            'style': '{',
        },
    },
    'handlers': {
        'stderr': {
            'level': 'ERROR',
            'class': 'logging.StreamHandler',
            'stream': sys.stderr,
            'formatter': 'verbose',
        },
        'stdout': {
            'level': 'INFO',
            'class': 'logging.StreamHandler',
            'stream': sys.stdout,
            'formatter': 'verbose',
        },
        'mail_admins': {
            'level': 'ERROR',
            'class': 'django.utils.log.AdminEmailHandler',
        },
    },
    'loggers': {
        'django': {
            'handlers': ['stderr', 'stdout', ],
            'level': 'INFO',
            'propagate': True,
        },
        'pyas2': {
          'handlers': ['stdout', 'stderr', 'mail_admins'],
          'level': 'INFO',
          'propagate': True,
        },
        'filewatcher': {
          'handlers': ['stdout', 'stderr', 'mail_admins'],
          'level': 'INFO',
          'propagate': True,
        },
        'pyas2lib': {
          'handlers': ['stdout', 'stderr', 'mail_admins'],
          'level': 'INFO',
          'propagate': True,
        },
    },
}