Programming Examples

ChilkatHOMEASPVisual BasicVB.NETC#Visual C++CMFCDelphiFoxProJavaPerlPHPPythonRubySQL ServerVBScript

C Examples

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


 

 

 

 

 

 

 

 

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.

Download Chilkat C/C++ Libraries for VC++ 9.0 / Win32

Download Chilkat C/C++ Libraries for VC++ 8.0 / Win32

Download Chilkat C/C++ 64-bit Libraries for VC++ 8.0 / x64

Download Chilkat Visual Studio 2005 C/C++ Libs for Windows Mobile, Pocket PC, SmartPhone, WinCE

Download Chilkat C/C++ Libraries for VC++ 7.0 / Win32

Download Chilkat C/C++ Libraries for VC++ 6.0 / Win32

Download Chilkat C/C++ Libraries for VC++ 6.0, Win 95/98/NT4 Compatible

#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-2008 Chilkat Software, Inc. All Rights Reserved.