Hello,

I did this recently with postfix.

These are my notes:

[add to /etc/aliases]
support:        "|/home/support/support.py"

[add to /etc/postfix/virtual]
t...@thesupport.com  support

* then run newaliases

And my script looks like this:

#!/usr/bin/python

import sys, time, email, email.Message, email.Errors, email.Utils, smtplib,
os, socket, random
from datetime import date
from email.Iterators import typed_subpart_iterator
from time import sleep

def get_charset(message, default="ascii"):
    """Get the message charset"""

    if message.get_content_charset():
        return message.get_content_charset()

    if message.get_charset():
        return message.get_charset()

    return default

# Taken from here, with thanks -
http://ginstrom.com/scribbles/2007/11/19/parsing-multilingual-email-with-python/
def get_body(message):
    """Get the body of the email message"""

    if message.is_multipart():
        #get the plain text version only
        text_parts = [part
                      for part in typed_subpart_iterator(message,
                                                         'text',
                                                         'plain')]
        body = []
        for part in text_parts:
            charset = get_charset(part, get_charset(message))
            body.append(unicode(part.get_payload(decode=True),
                                charset,
                                "replace"))

        return u"\n".join(body).strip()

    else: # if it is not multipart, the payload will be a string
          # representing the message body
        body = unicode(message.get_payload(decode=True),
                       get_charset(message),
                       "replace")
        return body.strip()

logfile = open('/home/support/support.txt','a')
raw_msg = sys.stdin.read()
emailmsg = email.message_from_string(raw_msg)

# Extract database Fields from mail
msgfrom = emailmsg['From']
msgto =  emailmsg['To']
msgsubj = emailmsg['Subject']
msgbody = get_body(emailmsg)

# Write a log file in /tmp with a record of the e-mails
currtime = date.today().strftime("%B %d, %Y")
logfile.write(currtime + "\n")
logfile.write("From: " + msgfrom + "\n")
logfile.write("To: " + msgto + "\n")
logfile.write("Subject: " + msgsubj + "\n")
logfile.write("Body: " + msgbody + "\n\n")
logfile.close()

################

Hope this might help someone

~Mike

On Sat, Aug 11, 2012 at 6:21 AM, Marwan Al-Sabbagh <
marwan.alsabb...@gmail.com> wrote:

> It's a very cool idea. I wanted to do something similar to this where I
> would email users notification for approvals and they could reply to the
> email with their approval. I'm curious you said you have already
> implemented this. How did you end up doing it.
>
>
> On 10 August 2012 18:23, Paul Backhouse <pa...@aptivate.org> wrote:
>
>> Hi there,
>>
>> The Django site I'm working on at the moment sends out emails when
>> content is created/updated, using django-notifications.
>>
>> A feature I would like to add is where users can reply to these mails,
>> ie comment on a topic. This reply then appears updated on the site.
>>
>> I've already written something that does this, but it's very application
>> specific.
>>
>> Ideally it would be done in a generic way (as its own app), with
>> something in the admin interface to set up the email account, and then
>> maybe a list of ordered filters to pass over the email and consequently
>> generate various model instances.
>>
>> Has this already been done? Does my google-fu escape me? If it hasn't
>> already been done, why not? And are there any modules out there that can
>> be dropped in to speed development? Any tips on developing this app?
>>
>> Thanks,
>>
>> Paul
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To post to this group, send email to django-users@googlegroups.com.
>> To unsubscribe from this group, send email to
>> django-users+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/django-users?hl=en.
>>
>>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to