Re: Receiving emails via app

2008-10-27 Thread Jeff Anderson
James Bennett wrote:
> On Sat, Oct 25, 2008 at 2:09 PM, Jeff Anderson <[EMAIL PROTECTED]> wrote:
>   
>> We have an alias set up in postfix that sends the e-mail to our script
>> via a pipe.
>>
>> The python script imports our Django models, and parses the e-mail
>> message with the email module, and does what it needs to.
>> 
>
> You can also use Python's built-in SMTP server module to set up a
> lightweight server process, and have your regular MTA forward messages
> to it. This lets the entire mail-processing routine happen in Python,
> which is often a bit easier to set up.
>
> See Doug Hellmann's recent PyMOTW article on this for some basic
> details: http://blog.doughellmann.com/2008/10/pymotw-smtpd.html
>   

This sounds like the best of both worlds option. One python process for
all e-mails without the overhead of having to check the e-mail
passively. A second server still needs to be run, but if you aren't
already running a mail server that "disadvantage" goes away. I may
consider switching to this.


Jeff Anderson



signature.asc
Description: OpenPGP digital signature


Re: Receiving emails via app

2008-10-26 Thread Steve Holden

felix wrote:
> In general I agree with Jeff's suggestion.  
>
> but OTOH you might be able to get pop to work
> and using the pop interface maybe you can get the headers in a clean
> pythonic fashion.
>
> it sounds like you will also have to deal with attachments, so maybe
> the pop library can handle that nicely.
>
Nope. poplib is simply for accessing the message from the POP server.
Jeff's suggestion would not, as you correctly identified, give access to
the headers. But processing MIME-structured messages requires the email
module no matter what method of delivery you choose.

regards
 Steve


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Receiving emails via app

2008-10-26 Thread James Bennett

On Sat, Oct 25, 2008 at 2:09 PM, Jeff Anderson <[EMAIL PROTECTED]> wrote:
> We have an alias set up in postfix that sends the e-mail to our script
> via a pipe.
>
> The python script imports our Django models, and parses the e-mail
> message with the email module, and does what it needs to.

You can also use Python's built-in SMTP server module to set up a
lightweight server process, and have your regular MTA forward messages
to it. This lets the entire mail-processing routine happen in Python,
which is often a bit easier to set up.

See Doug Hellmann's recent PyMOTW article on this for some basic
details: http://blog.doughellmann.com/2008/10/pymotw-smtpd.html


-- 
"Bureaucrat Conrad, you are technically correct -- the best kind of correct."

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Receiving emails via app

2008-10-26 Thread Jeff Anderson
AndyB wrote:
> This sounds like exactly what I need to do. However my Unix-fu isn't
> up to coping with the sentence 'We have an alias set up in postfix
> that sends the e-mail to our script via a pipe.'... :(
>
> My naive assumption is that one could use something like poplib in the
> standard library to connect to a POP3 server and process incoming
> emails that way. Does that sound a sensible route to take?
>   
It does sound sensible, but a heck of a lot more complicated than
setting up an alias.

If you use postfix, all you need to do is add one line to your
/etc/aliases file and run newaliases. Here are the few lines in our
postfix aliases file:

tick:   "|/git/tick/tickets/email_process.py /git comment"
closed-ticket:  "|/git/tick/tickets/email_process.py /git closed"
open-ticket:"|/git/tick/tickets/email_process.py /git open"

Ours is a ticket system called tick. we have an 'email_process.py' that
takes two arguments- /git is a directory to prepend to the
PYTHONPATH.the last argument is the type of e-mail message we are
processing. We also have a ticket open handler, and a ticket close
handler, but we don't use them.

It seems like running a Python process constantly to check pop3 is more
overhead, and an additional service to run. If you are already running
postfix, an alias is a really simple and efficient way to get e-mail
messages processed on the fly as they are received. The disadvantage is
that each time a message is received, a python interpretor is loaded
into memory. If you will be handling more than 1 or two messages a
minute, I'd definitely go for the pop3 route, and have the python
process stay loaded in memory. It'd put a decent amount of load on the
mailserver to constantly check and download hundreds of messages all the
time, but my guess is that it might be less load than loading several
hundred instances of a python interpretor. It'd be interesting to test.


Jeff Anderson



signature.asc
Description: OpenPGP digital signature


Re: Receiving emails via app

2008-10-26 Thread Doug B

poplib is pretty easy to work with:

def check_pop3(server,user,password):
import email,poplib,string
messages=[]
s=poplib.POP3(server)
s.user(user)
s.pass_(password)
resp, items, octets = s.list()
todelete=[]
for item in items:
id,size=item.split()
resp,text,octets = s.retr(id)
text = string.join(text, "\n")
message=email.message_from_string(text)
messages.append(message)
todelete.append(id) # flag for deletion
for id in todelete:
pass #s.dele(id)
s.quit()
return messages
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Receiving emails via app

2008-10-26 Thread felix
In general I agree with Jeff's suggestion.

but OTOH you might be able to get pop to work
and using the pop interface maybe you can get the headers in a clean
pythonic fashion.

it sounds like you will also have to deal with attachments, so maybe the pop
library can handle that nicely.


the script way is this:

In a hosted environment you often have the possibility to set up (using the
host company's control panel) a recipe or similar that sends an email to a
python shell script.  the script then receives the whole raw email on STDIN
standard in.
If you control the server yourself, then you should be able to use postfix
or whatever your email MTA is and again send the email to a shell script.

so the recipe or command to execute is something like:

/Library/Frameworks/Python.framework/Versions/Current/bin/python
/full/path/to/yourhandler.py


yourhandler.py can then get the entire body of the email (with all headers)
via STDIN standard in.

lines = sys.stdin.readlines()

it then can use pattern matching to find the from address in the headers
etc.
there's probably some nice libraries that do this parsing already.

alternatively you might be able to just dump the email to a file in a
directory
and later process the mails.

or access the Maildir/new for that account directly.

and then have a regular process that checks for new mails in the directory
and processes them.

either write a command that can be executed from manage.py (so you'll have
the whole django stack and all of your apps avail to you)
or import the settings and the most minimal amount of django that you'll
need.

or if you are really lazy, just write a view that processes the mails and
set a cron to fetch the page every once in a while ( just wget or curl it )


-felix



On Sun, Oct 26, 2008 at 8:13 PM, AndyB <[EMAIL PROTECTED]> wrote:

>
> This sounds like exactly what I need to do. However my Unix-fu isn't
> up to coping with the sentence 'We have an alias set up in postfix
> that sends the e-mail to our script via a pipe.'... :(
>
> My naive assumption is that one could use something like poplib in the
> standard library to connect to a POP3 server and process incoming
> emails that way. Does that sound a sensible route to take?
>
> Andy Baker
>
> On Oct 25, 7:09 pm, Jeff Anderson <[EMAIL PROTECTED]> wrote:
> > umit wrote:
> > > Hi, i am trying to build a quick blog system. But i want users can
> > > send emails to submit messages with pictures.
> > > How can i receive emails and process them? What should i use?
> >
> > We use Python's email module.
> >
> > We have an alias set up in postfix that sends the e-mail to our script
> > via a pipe.
> >
> > The python script imports our Django models, and parses the e-mail
> > message with the email module, and does what it needs to.
> >
> > This should give you a decent starting point.
> >
> > Cheers!
> >
> > Jeff Anderson
> >
> >  signature.asc
> > < 1KViewDownload
> >
>

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Receiving emails via app

2008-10-26 Thread AndyB

This sounds like exactly what I need to do. However my Unix-fu isn't
up to coping with the sentence 'We have an alias set up in postfix
that sends the e-mail to our script via a pipe.'... :(

My naive assumption is that one could use something like poplib in the
standard library to connect to a POP3 server and process incoming
emails that way. Does that sound a sensible route to take?

Andy Baker

On Oct 25, 7:09 pm, Jeff Anderson <[EMAIL PROTECTED]> wrote:
> umit wrote:
> > Hi, i am trying to build a quick blog system. But i want users can
> > send emails to submit messages with pictures.
> > How can i receive emails and process them? What should i use?
>
> We use Python's email module.
>
> We have an alias set up in postfix that sends the e-mail to our script
> via a pipe.
>
> The python script imports our Django models, and parses the e-mail
> message with the email module, and does what it needs to.
>
> This should give you a decent starting point.
>
> Cheers!
>
> Jeff Anderson
>
>  signature.asc
> < 1KViewDownload
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Receiving emails via app

2008-10-25 Thread Jeff Anderson
umit wrote:
> Hi, i am trying to build a quick blog system. But i want users can
> send emails to submit messages with pictures.
> How can i receive emails and process them? What should i use?
>   
We use Python's email module.

We have an alias set up in postfix that sends the e-mail to our script
via a pipe.

The python script imports our Django models, and parses the e-mail
message with the email module, and does what it needs to.

This should give you a decent starting point.


Cheers!

Jeff Anderson



signature.asc
Description: OpenPGP digital signature


Receiving emails via app

2008-10-25 Thread umit

Hi, i am trying to build a quick blog system. But i want users can
send emails to submit messages with pictures.
How can i receive emails and process them? What should i use?

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---