datatracker/ietf/bin/send-scheduled-mail
Henrik Levkowetz 9ea9ba1d66 Merged in [7138] from rjsparks@nostrum.com:
Reworked SMTP Exception handling, adding sending a ticket to the secretariat when there are errors handing messages off for delivery.
Added SMTP exception handling to send-scheduled-mail.
This is related to ticket #1208
 - Legacy-Id: 7256
Note: SVN reference [7138] has been migrated to Git commit 64727c1c33
2014-02-17 18:55:37 +00:00

35 lines
1.1 KiB
Python
Executable file

#!/usr/bin/env python
import datetime, os, sys
import syslog
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "ietf.settings")
from ietf.utils.mail import smtp_error_logging
from smtplib import SMTPException
syslog.openlog(os.path.basename(__file__), syslog.LOG_PID, syslog.LOG_USER)
if len(sys.argv) != 2 or sys.argv[1] not in ('all', 'rsync', 'specific'):
print "USAGE: %s <all | specific>" % os.path.basename(__file__)
print "'all' means all not sent"
print "'specific' means all not sent that are due to be sent"
sys.exit(1)
from ietf.message.utils import send_scheduled_message_from_send_queue
from ietf.message.models import SendQueue
mode = sys.argv[1]
now = datetime.datetime.now()
needs_sending = SendQueue.objects.filter(sent_at=None).select_related("message")
if mode == "specific":
needs_sending = needs_sending.exclude(send_at=None).filter(send_at__lte=now)
for s in needs_sending:
with smtp_error_logging(send_scheduled_message_from_send_queue) as send:
send(s)
syslog.syslog(u'Sent scheduled message %s "%s"' % (s.id, s.message.subject))