2 # -*- coding: utf-8 -*-
4 # This script sends out the report emails.
6 # Important: When testing, edit ‘config.py’ and set ‘reply_override’
7 # to your own email address. For production use, set it to ‘None’.
10 from email.mime.text import MIMEText
17 connection = pika.BlockingConnection(pika.ConnectionParameters(
18 host = config.mq_server))
19 channel = connection.channel()
21 smtp = smtplib.SMTP(config.smtp_server)
25 channel.basic_ack(delivery_tag = method.delivery_tag)
28 method, _, body = channel.basic_get(queue = 'patchq_reports',
32 to, subject, ref, content = json.loads(body)
34 if config.reply_override is not None:
35 to = [config.reply_override]
37 # If the content is over 50K then truncate it to the last 50K.
38 # XXX Upload full logs to a website.
39 if len(content) > 50000:
40 content = content[-50000:]
42 # Construct an email of type text/plain with the body of the
44 msg = MIMEText(content)
45 msg['Subject'] = subject
46 msg['From'] = email.utils.formataddr(config.from_address)
47 msg['To'] = ",".join([email.utils.formataddr(t) for t in to])
48 msg['In-Reply-To'] = ref
49 msg['References'] = ref
52 smtp.sendmail(config.from_address[1],
53 [email.utils.formataddr(t) for t in to],
57 # We've sent the reply, so ack the message.
62 print ("Sent %d emails." % emails)