Chilkat HOME ASP Visual Basic VB.NET C# Visual C++ C MFC Delphi FoxPro Java Perl PHP Python Ruby SQL Server VBScript
|
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. LOCAL loImap LOCAL lnSuccess LOCAL loCertStore LOCAL loCert LOCAL loCert2 LOCAL loMessageSet LOCAL lnFetchUids LOCAL loBundle LOCAL i LOCAL loEmail loImap = CreateObject('Chilkat.Imap') * Anything unlocks the component and begins a fully-functional 30-day trial. lnSuccess = loImap.UnlockComponent("Anything for 30-day trial") IF (lnSuccess <> 1) THEN =MESSAGEBOX(loImap.LastErrorText) QUIT ENDIF * To use a secure SSL connection, set SSL and the port: loImap.Ssl = 1 * The typical port for IMAP SSL is 993 loImap.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.) loCertStore = CreateObject('Chilkat.CertStore') * The 1st argument is the filename, the 2nd arg is the * PFX file's password: lnSuccess = loCertStore.LoadPfxFile("myCertWithPrivateKey.pfx","secret") IF (lnSuccess <> 1) THEN =MESSAGEBOX(loCertStore.LastErrorText) QUIT ENDIF * Find the certificate by the subject common name: loCert = loCertStore.FindCertBySubjectCN("Chilkat Software, Inc.") IF (loCert = NULL ) THEN =MESSAGEBOX(loCertStore.LastErrorText) QUIT ENDIF * 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: loCert2 = CreateObject('Chilkat.Cert') * The 1st argument is the filename, the 2nd arg is the * PFX file's password: lnSuccess = loCert2.LoadPfxFile("tagtooga_secret.pfx","secret") IF (lnSuccess <> 1) THEN =MESSAGEBOX(loCert.LastErrorText) QUIT ENDIF * Use the cert: loImap.SetSslClientCert(loCert) * Connect to an IMAP server. lnSuccess = loImap.Connect("mail.chilkatsoft.com") IF (lnSuccess <> 1) THEN =MESSAGEBOX(loImap.LastErrorText) QUIT ENDIF * Login lnSuccess = loImap.Login("myLogin","myPassword") IF (lnSuccess <> 1) THEN =MESSAGEBOX(loImap.LastErrorText) QUIT ENDIF * Select an IMAP mailbox lnSuccess = loImap.SelectMailbox("Inbox") IF (lnSuccess <> 1) THEN =MESSAGEBOX(loImap.LastErrorText) QUIT ENDIF * We can choose to fetch UIDs or sequence numbers. lnFetchUids = 1 * Get the message IDs of all the emails in the mailbox loMessageSet = loImap.Search("ALL",lnFetchUids) IF (loMessageSet = NULL ) THEN =MESSAGEBOX(loImap.LastErrorText) QUIT ENDIF * Fetch the emails into a bundle object: loBundle = loImap.FetchBundle(loMessageSet) IF (loBundle = NULL ) THEN RELEASE loMessageSet =MESSAGEBOX(loImap.LastErrorText) QUIT ENDIF * Loop over the bundle and display the FROM and SUBJECT of each. FOR i = 0 TO loBundle.MessageCount - 1 loEmail = loBundle.GetEmail(i) ? loEmail.From ? loEmail.Subject ? "--" RELEASE loEmail NEXT * Disconnect from the IMAP server. loImap.Disconnect() RELEASE loMessageSet RELEASE loBundle |
Need a specific example? Send a request to support@chilkatsoft.com
© 2000-2010 Chilkat Software, Inc. All Rights Reserved.
Mail Component · .NET Email Component · ASP Mail Component · XML Parser