One way that I've solved this in the past was using qmail's .qmail
files (docs).
Basically you set up qmail and point your email address (for ease of use, lets assume [email protected] is your email address) to your home directory. In that directory you set up a .qmail-proc
file to handle the mail.
This allows you to use a full-fledged SMTP server on your server, including spam filtering, forwarding, aliases, all that fun stuff. You can then pipe the data from an email into an application. In your case, I would suggest making a Mangement Command in Django to process the email (I'll call it proc_email
). Thus your .qmail-proc
may look like:
/var/spool/mail/proc
| /www/django/myproject/manage.py proc_email
This stores a copy of the email in /var/spool/mail/proc
, then passes the email to the script in the second line. The email itself is passed to proc_email
via sys.stdin
. Simply read the email from there, and store it through your Django Models.
If you need to process email for different addresses later, you can also set up aliases which point to your home directory, and use .qmail-<username>
files for each alias. Allowing you to pass other flags (such as the username for each alias) to proc_email
if needed.
I should note that this isn't the simplest solution, but it can scale, and is pretty darn bullet proof.