Visual FoxPro
Visual FoxPro
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 Visual FoxPro Downloads
LOCAL lnSuccess
LOCAL loMailman
LOCAL loCert
lnSuccess = 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.
loMailman = CreateObject('Chilkat.MailMan')
* Configure the SMTP server connection.
loMailman.SmtpHost = "smtp.example.com"
loMailman.SmtpPort = 465
loMailman.SmtpSsl = 1
loMailman.SmtpUsername = "user@example.com"
loMailman.SmtpPassword = "myPassword"
* Establish the TLS connection.
lnSuccess = loMailman.SmtpConnect()
IF (lnSuccess = 0) THEN
? loMailman.LastErrorText
RELEASE loMailman
CANCEL
ENDIF
* Get the certificate the SMTP server presented (useSmtp = 1).
loCert = CreateObject('Chilkat.Cert')
lnSuccess = loMailman.GetServerCert(1,loCert)
IF (lnSuccess = 0) THEN
? loMailman.LastErrorText
RELEASE loMailman
RELEASE loCert
CANCEL
ENDIF
? "Server certificate subject (CN): " + loCert.SubjectCN
? "Issued by: " + loCert.IssuerCN
lnSuccess = loMailman.CloseSmtpConnection()
IF (lnSuccess = 0) THEN
? loMailman.LastErrorText
RELEASE loMailman
RELEASE loCert
CANCEL
ENDIF
RELEASE loMailman
RELEASE loCert