Kevin Hanson
Kevin Hanson

Reputation: 25

Determine TLS support BEFORE sending email

We have a system that can send emails using TLS. However, we only want to send full email w/attachments if the destination supports TLS. IF it does not support TLS, we send a different message without attachments.

We used to just try sending with TLS and waiting for the receiver to "fail" back to us, then send the backup message. Recently, we switched to relaying through Frontbridge for all of our outgoing messages. However, Frontbridge will send a message using TLS if it can, or without if it can't. We've lost the ability to customize our message based on TLS support.

The question is this: in a .NET C# web app, how can I tell if a destination supports TLS BEFORE sending anything? That way we can customize the message BEFORE relaying it through Frontbridge.

I need to be able to do this programmatically, but I don't want to have to add a whole library to our solution (like Minimalistic Telnet), because we don't need full telnet functionality... I just need to ping to server and ask it what it supports!

Can that be done simply using the System.Net.Sockets stuff??

Thanks, Kevin

Upvotes: 0

Views: 206

Answers (1)

Yes, you need to write part of SMTP protocol.

For explicit TLS mode: You connect, receive and send data, then send STARTTLS command and see if the response is 220. Then you should close connection.

For implicit TLS you would need to emulate or use an SSL/TLS client: send initial request, check the response and disconnect.

As you don't want to use external libraries, I can't recommend you our SecureBlackbox, whose SMTP component lets you do what you need in a dozen of lines of code.

Upvotes: 1

Related Questions