def process_notification(notification):
from ..models.notification import (
NotificationDeliveryStateType, UnverifiedEmailException,
MissingEmailException)
import smtplib
import socket
from assembl.lib import config
assert notification
sys.stderr.write(
"process_notification called with notification %d, state was %s" % (
notification.id, notification.delivery_state))
if notification.delivery_state not in \
NotificationDeliveryStateType.getRetryableDeliveryStates():
sys.stderr.write(
"Refusing to process notification %d because its delivery state is: %s" % (
notification.id, notification.delivery_state))
return
try:
email = notification.render_to_message()
# sys.stderr.write(email_str)
recipient = notification.get_to_email_address()
wait_if_necessary(recipient)
notify_process_mailer.send_immediately(email, fail_silently=False)
notification.delivery_state = \
NotificationDeliveryStateType.DELIVERY_IN_PROGRESS
email_was_sent(recipient)
except UnverifiedEmailException as e:
sys.stderr.write("Not sending to unverified email: "+repr(e))
notification.delivery_state = \
NotificationDeliveryStateType.DELIVERY_TEMPORARY_FAILURE
except MissingEmailException as e:
notification.delivery_state = \
NotificationDeliveryStateType.DELIVERY_TEMPORARY_FAILURE
sys.stderr.write("Missing email! :"+repr(e))
except (smtplib.SMTPConnectError,
socket.timeout, socket.error,
smtplib.SMTPHeloError) as e:
sys.stderr.write("Temporary failure: "+repr(e))
notification.delivery_state = \
NotificationDeliveryStateType.DELIVERY_TEMPORARY_FAILURE
except smtplib.SMTPRecipientsRefused as e:
notification.delivery_state = \
NotificationDeliveryStateType.DELIVERY_FAILURE
sys.stderr.write("Recepients refused: "+repr(e))
except smtplib.SMTPSenderRefused as e:
notification.delivery_state = \
NotificationDeliveryStateType.DELIVERY_TEMPORARY_FAILURE
sys.stderr.write("Invalid configuration! :"+repr(e))
mark_changed()
sys.stderr.write(
"process_notification finished processing %d, state is now %s"
% (notification.id, notification.delivery_state))
评论列表
文章目录