Email Subscriptions

Note: Originally written December 30, 2008.

Concept

Allow users to subscribe to emails containing information in a wide variety of manners, similar to how they can subscribe to RSS feeds.

Features

  • Subscribe to specific types of data (models). For example, articles by a certain author, photos with a specific tag, content in a specific section, etc.
  • Specify how often a given subscription will collate and generate emails (immediately after posting, daily, weekly, arbitrary). If applicable, send multiple subscriptions collated in one email instead of multiple separate emails (include Table of Contents at top of email?).
  • Users control their subscriptions through their profile page.
    • A given subscription process can be initiated by a link (e.g., "Subscribe to this author") on any page on the site. After clicking the link, the user would be presented with any relevant options and prompted for confirmation. This should probably be exposed through template tags.
  • Choose between text or HTML formatting

Technical Design

  • EmailSubscription? model
    • django.contrib.ContentType? FK
    • object_id - int? list of ints?
    • frequency - # of times per day/week? maximum # of hours between emails?
    • last processed timestamp
    • text or html boolean
  • Template tag
    • Like countthis/emailthis/sharethis
    • Generates link to a view that handles the subscription process
  • Trigger(s)
    • save or "published" signal?
      • in the signal handler, check through all the EmailSubscription? model objects for ones that matches the appropriate set of criteria and process them
      • register with all models?
    • cron job?
  • Email sending
    • queue of emails stored in database
    • periodically (once per minute? every 5 minutes?) process x emails per run
    • weight/priority to control order in which emails get sent
      • registration, lost password, and other emails should get sent immediately (high priority)
      • subscriptions are not time-sensitive, so they can be lower priority
      • idea: if server load is high, only process emails above a given priority level (configurable) to avoid performance drop for non-time-sensitive emails
      • external (e.g., Google Apps) vs local (e.g., Exim) email server - need to test out and find performance tradeoffs