Chilkat HOME Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi DLL Go Java Node.js Objective-C PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(Node.js) Using Client Certificate w/ IMAP SSLDemonstrates how to use a client-side certificate with an IMAP SSL connection. The SetSslClientCert method is called to specify a certificate to be used for the SSL connection.
var os = require('os'); if (os.platform() == 'win32') { var chilkat = require('@chilkat/ck-node23-win64'); } else if (os.platform() == 'linux') { if (os.arch() == 'arm') { var chilkat = require('@chilkat/ck-node23-linux-arm'); } else if (os.arch() == 'arm64') { var chilkat = require('@chilkat/ck-node23-linux-arm64'); } else { var chilkat = require('@chilkat/ck-node23-linux-x64'); } } else if (os.platform() == 'darwin') { var chilkat = require('@chilkat/ck-node23-mac-universal'); } function chilkatExample() { // This example assumes the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. var imap = new chilkat.Imap(); // To use a secure SSL connection, set SSL and the port: imap.Ssl = true; // The typical port for IMAP SSL is 993 imap.Port = 993; // Load a certificate from a PFX file and use it. // Note: Other methods are available to load pre-installed // certificates from registry-based certificate stores. // Create an instance of a certificate store object, load a PFX file, // locate the certificate we need, and use it for signing. // (a PFX file may contain more than one certificate.) var certStore = new chilkat.CertStore(); // The 1st argument is the filename, the 2nd arg is the // PFX file's password: var success = certStore.LoadPfxFile("myCertWithPrivateKey.pfx","secret"); if (success !== true) { console.log(certStore.LastErrorText); return; } // Find the certificate by the subject common name: // cert: Cert var cert; cert = certStore.FindCertBySubjectCN("Chilkat Software, Inc."); if (certStore.LastMethodSuccess == false) { console.log(certStore.LastErrorText); return; } // If a PFX file is known to contain a single certificate, // you may load it directly into a Chilkat certificate object. // This snippet of source code shows how: var cert2 = new chilkat.Cert(); // The 1st argument is the filename, the 2nd arg is the // PFX file's password: success = cert2.LoadPfxFile("myClientCert.pfx","secret"); if (success !== true) { console.log(cert.LastErrorText); return; } // Use the cert: success = imap.SetSslClientCert(cert); // Connect to an IMAP server. success = imap.Connect("imap.someMailServer.com"); if (success !== true) { console.log(imap.LastErrorText); return; } // Login success = imap.Login("myLogin","myPassword"); if (success !== true) { console.log(imap.LastErrorText); return; } // Select an IMAP mailbox success = imap.SelectMailbox("Inbox"); if (success !== true) { console.log(imap.LastErrorText); return; } // messageSet: MessageSet var messageSet; // We can choose to fetch UIDs or sequence numbers. var fetchUids = true; // Get the message IDs of all the emails in the mailbox messageSet = imap.Search("ALL",fetchUids); if (imap.LastMethodSuccess == false) { console.log(imap.LastErrorText); return; } // Fetch the emails into a bundle object: // bundle: EmailBundle var bundle; bundle = imap.FetchBundle(messageSet); if (imap.LastMethodSuccess == false) { console.log(imap.LastErrorText); return; } // Loop over the bundle and display the FROM and SUBJECT of each. var i = 0; var numEmails = bundle.MessageCount; while (i < numEmails) { // email: Email var email = bundle.GetEmail(i); console.log(email.From); console.log(email.Subject); console.log("--"); i = i+1; } // Disconnect from the IMAP server. success = imap.Disconnect(); } chilkatExample(); |
© 2000-2025 Chilkat Software, Inc. All Rights Reserved.