Search code examples
pythonemailpython-3.xproxysmtplib

Send mail with smtplib using proxy


I have a very basic piece of Python code:

    import smtplib
    server = smtplib.SMTP(host, port)
    problems = server.sendmail(from_addr, to_addr,  message)

Is there solution to run it behind an HTTP proxy? I am using Python 3.4.1 on Linux with the http_proxy variable set.

Now I am getting a timeout from SMTP, but if I run this code from a proxy-free network, it works OK.


Solution

  • Is there solution to run it behind an HTTP proxy?

    No, HTTP is a different protocol than SMTP and the proxy is for HTTP only. If you are very lucky you might be able to create a tunnel using the CONNECT command to the outside SMTP server, but usually the ports used for CONNECT are restricted so that you will not be able to create a tunnel to an outside host port 25 (i.e. SMTP).