How do I connect to an smtp server through a proxy using SSL in C#.NET?

Posted on 2009-02-23
Last Modified: 2013-11-30
I am writing a program to send mail and have come to a problem trying to get SSL to work with a proxy server as well. I have managed to successfully send mail using .NET's built in SmtpClient and enable TLS etc but I haven't found a way to do this routed through a proxy server. I have found a proxy socket implementation at which can connect to proxys which I have also got working but then I have to somehow implement the SSL communication manually which i'm really not sure how to do.
Question by:bossmonkey666
    LVL 11

    Expert Comment

    SSL and TLS are not compatible transport layers.

    Did you want to connect to an SMTP-SSL server or a SMTP-TLS Server?

    If it is SMTP-SSL then you can create a SSL Tunnel between your application and the endpoint via the proxy and then just use the SMTP Client as if you are talking to a non encrypted SSL Service.  If it is TLS then you will not be able to connect via the proxy unless it is a SOCKS/TLS proxy.


    Author Comment

    Oh I see, I was under the impression they were very similar protocols. Okay the SMTP servers i've tried are TLS I believe: and both need you to supply "STARTTLS" before you can give it the email information. So does this mean I would be looking out for SOCKS/TLS proxies only? Or is this possible through say SOCKS5
    LVL 11

    Accepted Solution

    While TLS and SSL are essentially the same from an encryption perspective, the fundamental difference is:

    TLS - Connects in Cleartext and then initiates SSL via the use of commands such as STARTTLS.

    SSL - Connects and straight away, begins an encrypted Hand-Shake process to establish an encrypted session.

    I believe the standard for SMTp-SSL is port 465, where as TLS is just an encrypted stream over that standard Port 25.

    For TLS you will need to use a SOCKS proxy server that allows you to make an outbound connection on port 25.


    Author Closing Comment


    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    Whats the use of master secret 4 33
    Find key in dictionary list 6 20
    VB.NET Server side Javascript 8 43
    Aspnet xml 2 27
    What is Usenet? There are many different opinions on exactly what Usenet is an isn't. Many opinions are incorrect simply out of ignorance. The Wikipedia listing about Usenet does a good job of explaining it, so instead of repeating it all here I wi…
    Microservice architecture adoption brings many advantages, but can add intricacy. Selecting the right orchestration tool is most important for business specific needs.
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now