]> git.ipfire.org Git - ipfire.org.git/blob - src/web/newsletter.py
people: Add congratulations page for activating the new account
[ipfire.org.git] / src / web / newsletter.py
1 #!/usr/bin/python3
2
3 import email.mime.text
4 import logging
5 import tornado.gen
6 import tornado.process
7
8 from . import base
9
10 class SubscribeHandler(base.BaseHandler):
11 @base.blacklisted
12 def prepare(self):
13 # Makes sure that we call blacklist for everything
14 pass
15
16 @tornado.gen.coroutine
17 def post(self):
18 address = self.get_argument("email")
19
20 # Create an email with us as sender
21 m = email.mime.text.MIMEText("")
22 m.add_header("To", "ipfire-announce-join@lists.ipfire.org")
23 m.add_header("From", address)
24 m.add_header("Sender", "no-reply@ipfire.org")
25 m.add_header("Subject", "Subscribe")
26
27 logging.debug("Sending email:\n%s" % m.as_string())
28
29 # Call sendmail
30 p = tornado.process.Subprocess(["sendmail", "-t"],
31 stdin=tornado.process.Subprocess.STREAM)
32
33 # Pipe the email into sendmail
34 yield tornado.gen.Task(p.stdin.write, m.as_bytes())
35
36 # Close standard input
37 p.stdin.close()
38
39 # Wait until sendmail is done
40 ret = yield p.wait_for_exit()
41
42 logging.info("%s has subscribed to the newsletter" % address)
43
44 self.render("newsletter/subscribed.html", address=address)