Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Email event notifications. #106

Open
zalejus opened this issue Nov 28, 2023 · 1 comment
Open

Email event notifications. #106

zalejus opened this issue Nov 28, 2023 · 1 comment

Comments

@zalejus
Copy link

zalejus commented Nov 28, 2023

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)
@chadgates
Copy link
Contributor

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,
        },
    },
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants