]> git.ipfire.org Git - ipfire.org.git/blobdiff - src/backend/messages.py
blog: Send out emails for posts
[ipfire.org.git] / src / backend / messages.py
index 69dbf802f545d1bba2f3027e5df210594bc93d80..f1481f11a9d0c8c7198024d5316569f936d1893e 100644 (file)
@@ -5,6 +5,7 @@ import email.mime.multipart
 import email.mime.text
 import email.utils
 import logging
+import random
 import subprocess
 import tornado.locale
 import tornado.template
@@ -32,7 +33,7 @@ class Messages(misc.Object):
        def make_recipient(self, recipient):
                # Use the contact instead of the account
                if isinstance(recipient, accounts.Account):
-                       recipient = "%s <%s>" % (recipient, recipient.email)
+                       recipient = account.email_to
 
                # Fall back to pass on strings
                return recipient
@@ -159,6 +160,8 @@ class Messages(misc.Object):
                """
                account = self.backend.accounts.get_by_mail(recipient)
 
+               posts = list(self.backend.blog.get_newest(limit=5))
+
                kwargs = {
                        "account"    : account,
                        "first_name" : account.first_name,
@@ -169,6 +172,9 @@ class Messages(misc.Object):
                        # Random activation/reset codes
                        "activation_code" : util.random_string(36),
                        "reset_code"      : util.random_string(64),
+
+                       # The latest blog post
+                       "post" : random.choice(posts),
                }
 
                return self.send_template(template, recipients=[recipient,], **kwargs)