Classic ASP
Classic ASP
Get the SMTP or POP3 Server's TLS Certificate
See more SMTP Examples
Demonstrates the Chilkat MailMan.GetServerCert method, which gets the digital certificate presented by the SMTP or POP3 server for the current SSL/TLS connection and stores it in a Cert object. Pass true for the SMTP server's certificate or false for the POP3 server's. This example connects to the SMTP server and prints the certificate's subject and issuer.
Background: During a TLS handshake the server presents a certificate proving its identity, and the client validates it against trusted authorities. Retrieving that certificate lets you inspect it yourself — checking the subject, issuer, or expiration for auditing, logging, or certificate-pinning style checks. It must be called while a TLS connection is established, since the certificate belongs to that specific session.
Chilkat Classic ASP Downloads
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<%
success = 0
' Demonstrates the MailMan.GetServerCert method, which gets the digital certificate
' presented by the SMTP or POP3 server for the current SSL/TLS connection. Pass 1 for
' the SMTP server's certificate, or 0 for the POP3 server's certificate.
set mailman = Server.CreateObject("Chilkat.MailMan")
' Configure the SMTP server connection.
mailman.SmtpHost = "smtp.example.com"
mailman.SmtpPort = 465
mailman.SmtpSsl = 1
mailman.SmtpUsername = "user@example.com"
mailman.SmtpPassword = "myPassword"
' Establish the TLS connection.
success = mailman.SmtpConnect()
If (success = 0) Then
Response.Write "<pre>" & Server.HTMLEncode( mailman.LastErrorText) & "</pre>"
Response.End
End If
' Get the certificate the SMTP server presented (useSmtp = 1).
set cert = Server.CreateObject("Chilkat.Cert")
success = mailman.GetServerCert(1,cert)
If (success = 0) Then
Response.Write "<pre>" & Server.HTMLEncode( mailman.LastErrorText) & "</pre>"
Response.End
End If
Response.Write "<pre>" & Server.HTMLEncode( "Server certificate subject (CN): " & cert.SubjectCN) & "</pre>"
Response.Write "<pre>" & Server.HTMLEncode( "Issued by: " & cert.IssuerCN) & "</pre>"
success = mailman.CloseSmtpConnection()
If (success = 0) Then
Response.Write "<pre>" & Server.HTMLEncode( mailman.LastErrorText) & "</pre>"
Response.End
End If
%>
</body>
</html>