templates_netbootdir = $(templatesdir)/netboot
templates_newsletter_DATA = \
+ src/templates/newsletter/subscribe.txt \
src/templates/newsletter/subscribed.html
templates_newsletterdir = $(templatesdir)/newsletter
except KeyError:
message.add_header(k, v)
+ # Read recipients from To: header
+ if not recipients:
+ recipients = message.get("To").split(", ")
+
# Add date if the message doesn't have one already
if "Date" not in message:
message.add_header("Date", email.utils.formatdate())
# Send the message
self._send(recipients, message.as_string(), priority=priority)
- def send_template(self, template_name, recipients,
+ def send_template(self, template_name, recipients=[],
sender=None, priority=0, headers={}, **kwargs):
"""
Send a message based on the given template
def post(self):
address = self.get_argument("email")
- # Create an email with us as sender
- m = email.mime.text.MIMEText("")
- m.add_header("To", "ipfire-announce-join@lists.ipfire.org")
- m.add_header("From", address)
- m.add_header("Sender", "no-reply@ipfire.org")
- m.add_header("Subject", "Subscribe")
-
- logging.debug("Sending email:\n%s" % m.as_string())
-
- # Call sendmail
- p = tornado.process.Subprocess(["sendmail", "-t"],
- stdin=tornado.process.Subprocess.STREAM)
-
- # Pipe the email into sendmail
- yield tornado.gen.Task(p.stdin.write, m.as_bytes())
-
- # Close standard input
- p.stdin.close()
-
- # Wait until sendmail is done
- ret = yield p.wait_for_exit()
+ with self.db.transaction():
+ self.backend.messages.send_template(
+ "newsletter/subscribe", address=address)
logging.info("%s has subscribed to the newsletter" % address)