Alex,<br><br>That link was invaluable. <br><br>Twisted docs + project deadlines + my own ignorance = I completely had the wrong idea about how to set up SSL. Code worked like a charm, and now I'm very happy not to have to finish the project using python's native imaplib. <br>
<br>I'll certainly share the fruits of my labour with this list.<br><br>Thanks again....<br><br><br><div class="gmail_quote">On Fri, Jun 12, 2009 at 4:40 AM, Alex Clemesha <span dir="ltr"><<a href="mailto:clemesha@gmail.com">clemesha@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Hi,<br>
<br>
I've wondered myself how to do this, so thanks Phil.<br>
<br>
I extended Phil's solution to work with Gmail, which boils<br>
down to using SSL and setting the correct servername and port, see here:<br>
<a href="http://gist.github.com/128521" target="_blank">http://gist.github.com/128521</a><br>
<br>
Pywinder, you should be able to just change the username/password<br>
and it will work for you (you might have to have the python ssl module<br>
installed - post again if that is the case and it's not working for you)<br>
<br>
How to do useful stuff with the 'mailboxes' function in the script is<br>
another question (which I dont know the answer to). Maybe post<br>
your usage if you have a chance.<br>
<br>
<br>
-Alex<br>
<div><div></div><div class="h5"><br>
<br>
<br>
<br>
<br>
On Thu, Jun 11, 2009 at 5:45 PM, Pywinder<br>
Singh<<a href="mailto:pywinder@monkeydriveengine.com">pywinder@monkeydriveengine.com</a>> wrote:<br>
> Phil,<br>
><br>
> Much obliged.<br>
><br>
> Was able to isolate and confirm that the real issue is that login is hanging<br>
> for some reason, and causing the timeout message. I suspect SSL/TLS issues,<br>
> which at least gives me a decided place to start investigating.<br>
><br>
> Thanks again for the code, it was sanity inducing to say the least. ;)<br>
><br>
><br>
> Phil Mayers wrote:<br>
>><br>
>> Pywinder Singh wrote:<br>
>> ><br>
>> > Ideally, I'd love to see a snipped which is able to log into an imap<br>
>> > server and gets a list of mailboxes. If the example on the site works<br>
>><br>
>> Here you go:<br>
>><br>
>> #!/usr/bin/python<br>
>><br>
>> from twisted.internet import reactor, protocol, defer<br>
>> from twisted.mail import imap4<br>
>><br>
>> # change these...<br>
>> username = '?'<br>
>> password = '?'<br>
>> servername = '?'<br>
>><br>
>> def mailboxes(list):<br>
>> for flags,sep,mbox in list:<br>
>> print mbox<br>
>><br>
>> def loggedin(res, proto):<br>
>> d = proto.list('','*')<br>
>> d.addCallback(mailboxes)<br>
>> return d<br>
>><br>
>> def connected(proto):<br>
>> print "connected", proto<br>
>> d = proto.login(username, password)<br>
>> d.addCallback(loggedin, proto)<br>
>> return d<br>
>><br>
>> def failed(f):<br>
>> print "failed", f<br>
>> return f<br>
>><br>
>> def done(_):<br>
>> reactor.callLater(0, reactor.stop)<br>
>><br>
>> def main():<br>
>> c = protocol.ClientCreator(reactor, imap4.IMAP4Client)<br>
>> d = c.connectTCP(servername, 143)<br>
>> d.addCallbacks(connected, failed)<br>
>> d.addBoth(done)<br>
>><br>
>> reactor.callLater(0, main)<br>
>> reactor.run()<br>
>><br>
>><br>
>> This example makes use of deferred chaining i.e. returning a deferred<br>
>> from a callback handler, so you'll want to understand that.<br>
><br>
><br>
</div></div>> _______________________________________________<br>
> Twisted-Python mailing list<br>
> <a href="mailto:Twisted-Python@twistedmatrix.com">Twisted-Python@twistedmatrix.com</a><br>
<div class="im">> <a href="http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python" target="_blank">http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python</a><br>
><br>
><br>
<br>
<br>
<br>
--<br>
</div>Alex Clemesha<br>
<a href="http://clemesha.org" target="_blank">clemesha.org</a><br>
<br>
_______________________________________________<br>
Twisted-Python mailing list<br>
<a href="mailto:Twisted-Python@twistedmatrix.com">Twisted-Python@twistedmatrix.com</a><br>
<div><div></div><div class="h5"><a href="http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python" target="_blank">http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python</a><br>
</div></div></blockquote></div><br>