I am late for this party, but I offer my approach to any passers-by who may be interested in an alternative.
As noted in previous answers, the System.Net.Mail SmtpClient class SmtpClient not support implicit SSL. It supports Explicit SSL, which requires an insecure connection to the SMTP server through port 25 to negotiate transport layer security (TLS). I wrote about my torment with this subtlety here .
In short, SMTP through the Implict SSL port 465 requires that TLS be negotiated before connecting to the SMTP server. Instead of writing a .Net SMTPS implementation, I turned to a utility called Stunnel . This is a small service that allows you to redirect traffic on a local port to a remote port via SSL.
DISCLAIMER: Stunnel uses parts of the OpenSSL library, which recently had a high-profile exploit published in all major news technical facilities. I believe that the latest version uses the corrected OpenSSL, but please use at your own risk.
After installing the utility, a small addition to the configuration file:
; Example SSL client mode services [my-smtps] client = yes accept = 127.0.0.1:465 connect = mymailserver.com:465
... instructs the Stunnel service to forward local requests to port 465 to my mail server on port 465. This happens through TLS, which satisfies the SMTP server on the other end.
Using this utility, the following code will successfully transmit through port 465:
using System; using System.Net; using System.Net.Mail; namespace RSS.SmtpTest { class Program { static void Main( string[] args ) { try { using( SmtpClient smtpClient = new SmtpClient( "localhost", 465 ) ) {
Thus, the advantage is that you can use Implict SSL and port 465 as a security protocol, while still using the mail sending methods built into the framework. The disadvantage is that this requires the use of a third-party service, which may not be useful for anything other than this specific function.
Bob Mc Apr 10 '15 at 0:48 2015-04-10 00:48
source share