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 # Construct an email of type text/plain with the body of the
39 msg = MIMEText(content)
40 msg['Subject'] = subject
41 msg['From'] = email.utils.formataddr(config.from_address)
42 msg['To'] = ",".join([email.utils.formataddr(t) for t in to])
43 msg['In-Reply-To'] = ref
44 msg['References'] = ref
47 smtp.sendmail(config.from_address[1],
48 [email.utils.formataddr(t) for t in to],
52 # We've sent the reply, so ack the message.
57 print ("Sent %d emails." % emails)