Programming Examples

ChilkatHOMEAndroid™ASPVisual BasicVB.NETC#iOS (IPhone)Objective-CC++CMFCDelphiFoxProJavaPerl
PHP ExtensionPHP ActiveXPythonPowerShellRubySQL ServerVBScript

C Examples

Bounced Mail
Bz2
Certificates/Keys
Charset
CSV
DKIM / DomainKey
Diffie-Hellman
DSA
Email Object
Encryption
FileAccess
FTP
HTML Conversion
HTTP
IMAP
MHT / HTML Email
MIME
NTLM
POP3
RSA
SMTP
Socket
Spider
SSH Key
SSH
SSH Tunnel
SFTP
Tar
Upload
XML
Zip
Amazon S3

 

 

 

 

 

 

 

 

Send Signed Email using PFX File

Demonstrates how to send a signed email using a digital certificate w/ private key stored in a PFX file.

Downloads:

MS Windows Visual C/C++ Libraries
Linux/CentOS C/C++ Libraries
MAC OS X C/C++ Libraries
Solaris C/C++ Libraries
C++ Builder Libraries
#include <C_CkMailMan.h>
#include <C_CkEmail.h>
#include <C_CkCertStore.h>
#include <C_CkCert.h>

void ChilkatSample(void)
    {
    HCkMailMan mailman;
    BOOL success;
    HCkEmail email;
    HCkCertStore certStore;
    HCkCert cert;
    HCkCert cert2;

    //  The mailman object is used for sending and receiving email.
    mailman = CkMailMan_Create();

    //  Any string argument automatically begins the 30-day trial.

    success = CkMailMan_UnlockComponent(mailman,"30-day trial");
    if (success != TRUE) {
        printf("Component unlock failed\n");
        return;
    }

    //  Set the SMTP server.
    CkMailMan_putSmtpHost(mailman,"smtp.mymailserver.com");

    //  Create a new email object
    email = CkEmail_Create();

    CkEmail_putSubject(email,"This email is signed");
    CkEmail_putBody(email,"This is a digitally signed mail");
    CkEmail_putFrom(email,"Chilkat Admin <admin@chilkatsoft.com>");
    CkEmail_AddTo(email,"Chilkat Support","support@chilkatsoft.com");

    //  Indicate that the email should be sent signed.
    CkEmail_putSendSigned(email,TRUE);

    //  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.)
    certStore = CkCertStore_Create();
    //  The 1st argument is the filename, the 2nd arg is the
    //  PFX file's password:
    success = CkCertStore_LoadPfxFile(certStore,"chilkatsoft_secret.pfx","secret");
    if (success != TRUE) {
        printf("%s\n",CkCertStore_lastErrorText(certStore));
        return;
    }

    cert = CkCertStore_FindCertBySubjectE(certStore,"admin@chilkatsoft.com");
    if (cert == 0 ) {
        printf("%s\n",CkCertStore_lastErrorText(certStore));
        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:
    cert2 = CkCert_Create();
    //  The 1st argument is the filename, the 2nd arg is the
    //  PFX file's password:
    success = CkCert_LoadPfxFile(cert2,"chilkatsoft_secret.pfx","secret");
    if (success != TRUE) {
        printf("%s\n",CkCert_lastErrorText(cert));
        return;
    }

    //  This example will use the cert from the certStore...
    CkEmail_SetSigningCert(email,cert);

    //  Send a signed email.
    success = CkMailMan_SendEmail(mailman,email);
    if (success != TRUE) {
        printf("%s\n",CkMailMan_lastErrorText(mailman));
    }
    else {
        //  The LastErrorText property provides information
        //  even when successful.
        printf("%s\n",CkMailMan_lastErrorText(mailman));
        printf("Mail Sent!\n");
    }


    CkMailMan_Dispose(mailman);
    CkEmail_Dispose(email);
    CkCertStore_Dispose(certStore);
    CkCert_Dispose(cert2);

    }

Need a specific example? Send a request to support@chilkatsoft.com

© 2000-2010 Chilkat Software, Inc. All Rights Reserved.