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&#39;m very happy not to have to finish the project using python&#39;s native imaplib. <br>
<br>I&#39;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">&lt;<a href="mailto:clemesha@gmail.com">clemesha@gmail.com</a>&gt;</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&#39;ve wondered myself how to do this, so thanks Phil.<br>
<br>
I extended Phil&#39;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&#39;s not working for you)<br>
<br>
How to do useful stuff with the &#39;mailboxes&#39; 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&lt;<a href="mailto:pywinder@monkeydriveengine.com">pywinder@monkeydriveengine.com</a>&gt; wrote:<br>
&gt; Phil,<br>
&gt;<br>
&gt; Much obliged.<br>
&gt;<br>
&gt; Was able to isolate and confirm that the real issue is that login is hanging<br>
&gt; for some reason, and causing the timeout message. I suspect SSL/TLS issues,<br>
&gt; which at least gives me a decided place to start investigating.<br>
&gt;<br>
&gt; Thanks again for the code, it was sanity inducing to say the least. ;)<br>
&gt;<br>
&gt;<br>
&gt; Phil Mayers wrote:<br>
&gt;&gt;<br>
&gt;&gt; Pywinder Singh wrote:<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; Ideally, I&#39;d love to see a snipped which is able to log into an imap<br>
&gt;&gt; &gt; server and gets a list of mailboxes.  If the example on the site works<br>
&gt;&gt;<br>
&gt;&gt; Here you go:<br>
&gt;&gt;<br>
&gt;&gt; #!/usr/bin/python<br>
&gt;&gt;<br>
&gt;&gt; from twisted.internet import reactor, protocol, defer<br>
&gt;&gt; from twisted.mail import imap4<br>
&gt;&gt;<br>
&gt;&gt; # change these...<br>
&gt;&gt; username = &#39;?&#39;<br>
&gt;&gt; password = &#39;?&#39;<br>
&gt;&gt; servername = &#39;?&#39;<br>
&gt;&gt;<br>
&gt;&gt; def mailboxes(list):<br>
&gt;&gt;      for flags,sep,mbox in list:<br>
&gt;&gt;          print mbox<br>
&gt;&gt;<br>
&gt;&gt; def loggedin(res, proto):<br>
&gt;&gt;      d = proto.list(&#39;&#39;,&#39;*&#39;)<br>
&gt;&gt;      d.addCallback(mailboxes)<br>
&gt;&gt;      return d<br>
&gt;&gt;<br>
&gt;&gt; def connected(proto):<br>
&gt;&gt;      print &quot;connected&quot;, proto<br>
&gt;&gt;      d = proto.login(username, password)<br>
&gt;&gt;      d.addCallback(loggedin, proto)<br>
&gt;&gt;      return d<br>
&gt;&gt;<br>
&gt;&gt; def failed(f):<br>
&gt;&gt;      print &quot;failed&quot;, f<br>
&gt;&gt;      return f<br>
&gt;&gt;<br>
&gt;&gt; def done(_):<br>
&gt;&gt;      reactor.callLater(0, reactor.stop)<br>
&gt;&gt;<br>
&gt;&gt; def main():<br>
&gt;&gt;      c = protocol.ClientCreator(reactor, imap4.IMAP4Client)<br>
&gt;&gt;      d = c.connectTCP(servername, 143)<br>
&gt;&gt;      d.addCallbacks(connected, failed)<br>
&gt;&gt;      d.addBoth(done)<br>
&gt;&gt;<br>
&gt;&gt; reactor.callLater(0, main)<br>
&gt;&gt; reactor.run()<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt; This example makes use of deferred chaining i.e. returning a deferred<br>
&gt;&gt; from a callback handler, so you&#39;ll want to understand that.<br>
&gt;<br>
&gt;<br>
</div></div>&gt; _______________________________________________<br>
&gt; Twisted-Python mailing list<br>
&gt; <a href="mailto:Twisted-Python@twistedmatrix.com">Twisted-Python@twistedmatrix.com</a><br>
<div class="im">&gt; <a href="http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python" target="_blank">http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python</a><br>
&gt;<br>
&gt;<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>