This SSPI SChannel SMTPS example should compile and run in Visual Studio 2008 as is
http://www.coastrd.com/c-schannel-smtp (the original site seems dead; fortunately WaybackMachine has it archived)
SChannel is the Microsoft implementation of the GSS API that wraps the SSL/TLS protocol.
Advantages of utilizing SChannel:
- gory details are shielded from the developer by the SSPI.
- No extra setup is required to run the final application:
- SChannel is an integral part of the operating system
- On Windows ME/2000/XP/... platforms, SChannel is installed and configured by default
- SChannel calls follow GSS API standards.
- You do not need to create/install any certificates
- no third party dll's (1MB or larger) to ship and install
The code should produce a session that looks like this:
----- SSPI Initialized
----- WinSock Initialized
----- Credentials Initialized
----- Connectd To Server
70 bytes of handshake data sent
974 bytes of handshake data received
182 bytes of handshake data sent
43 bytes of handshake data received
Handshake was successful
----- Client Handshake Performed
----- Server Credentials Authenticated
Server subject: C=US, S=California, L=Mountain View, O=Google Inc, CN=smtp.gmail.com
Server issuer: C=ZA, S=Western Cape, L=Cape Town, O=Thawte Consulting cc, OU=Certification Services Division, CN=Thawte Premium Server CA, E=premium-server@thawte.com
----- Certificate Chain Displayed
----- Server Certificate Verified
----- Server certificate context released
Protocol: TLS1
Cipher: RC4
Cipher strength: 128
Hash: MD5
Hash strength: 128
Key exchange: RSA
Key exchange strength: 1024
----- Secure Connection Info
64 bytes of (encrypted) application data received
Decrypted data: 43 bytes
220 mx.google.com ESMTP 6sm17740567yxg.66
Sending 7 bytes of plaintext:
EHLO
28 bytes of encrypted data sent
169 bytes of (encrypted) application data received
Decrypted data: 148 bytes
250-mx.google.com at your service, [22.33.111.222]
250-SIZE 35651584
250-8BITMIME
250-AUTH LOGIN PLAIN
250-ENHANCEDSTATUSCODES
250 PIPELINING
Sending 7 bytes of plaintext:
QUIT
28 bytes of encrypted data sent
69 bytes of (encrypted) application data received
Decrypted data: 48 bytes
221 2.0.0 closing connection 6sm17740567yxg.66
----- SMTP session Complete
Sending Close Notify
23 bytes of handshake data sent
----- Disconnected From Server
----- Begin Cleanup
----- All Done -----