Choosing Source Address to Bind Socket to in IMAP Client

Prasad, Ramit ramit.prasad at
Tue Nov 20 23:41:13 CET 2012

brintoul at wrote:
> > > I have a multihomed machine that I would like to run the Python imaplib's IMAP4 client on.  I would like to be
> > > able to specify which interface the underlying socket will bind to as its source address.  How could I best do
> > > this?

> While I appreciate your attempt at humor, this is not information which helps me.  Perhaps you are not familiar
> with the basics of socket programming. This is all fine and dandy, and it is good to "know what you don't know".
> If you're interested, look at the third argument to "create_connection":

Apologies, I misread your question. 

According to the imaplib docs, you can subclass IMAP4 and override 
`` to create the socket and bind it to the desired interface.
You could also connect using IMAP4 and then close/reopen the socket
inside the IMAP4 connection object. 

I hope that is more help,

This email is confidential and subject to important disclaimers and
conditions including on offers for the purchase or sale of
securities, accuracy and completeness of information, viruses,
confidentiality, legal privilege, and legal entity disclaimers,
available at  

More information about the Python-list mailing list