Visual C++ Examples

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

C++ Examples

CkString
Byte Array
Bounced Mail
Bz2
Character Encoding
CSV
DH Key Exchange
DKIM/DomainKeys
Digital Certificates
Digital Signatures
DSA
Email
Email Object
Encryption
FTP
HTML Conversion
HTTP
IMAP
MHT / HTML Email
POP3
RSA
S/MIME
SMTP
Socket
Spider
SSH Key
SSH
SSH Tunnel
SFTP
Tar
Upload
XML
XMP
Zip Compression


More Examples...
Amazon S3
NTLM
FileAccess
RSS
Atom
Self-Extractor
Service
PPMD
Deflate
Bzip2
LZW

 

 

 

 

 

 

 

 

Send Encrypted Email

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

C++ source code to send public-key encrypted mail using a digital certificate.

#define _CRTDBG_MAP_ALLOC
#include <windows.h>
#include <stdio.h>
#include <crtdbg.h>

#include "C:/ck2000/components/ChilkatLib/Package/Include/CkSettings.h"
#include "C:/ck2000/components/ChilkatLib/Package/Include/CkCert.h"
#include "C:/ck2000/components/ChilkatLib/Package/Include/CkEmail.h"
#include "C:/ck2000/components/ChilkatLib/Package/Include/CkEmailBundle.h"
#include "C:/ck2000/components/ChilkatLib/Package/Include/CkMailMan.h"
#include "C:/ck2000/components/ChilkatLib/Package/Include/CkString.h"
#include "C:/ck2000/components/ChilkatLib/Package/Include/CkByteData.h"

void EmailExample(void)
    {
    CkMailMan mailman;

    // Any string passed to UnlockComponent begins the 30-day trial.
    bool unlocked = mailman.UnlockComponent("30-day trial");
    if (!unlocked)
	{
	printf("Failed to unlock component\n");
	return;
	}

    mailman.put_SmtpHost("mail.earthlink.net");
    
    // Send an encrypted email.
    CkEmail email;

    email.put_Body("This is the encrypted email body");

    email.put_FromAddress("matt@chilkatsoft.com");
    
    email.put_Subject("This is the email subject");

    // Load a certificate from a file and use it for encrypting.
    CkCert cert;
    cert.LoadFromFile("myCert.cer");

    // The To address must match the email address in the certificate:
    email.AddTo("Chilkat Support","support@chilkatsoft.com");

    // Check to make sure the certificate's email address matches.
    CkString certEmailAddr;
    cert.get_SubjectE(certEmailAddr);
    if (!certEmailAddr.equals("support@chilkatsoft.com"))
	{
	printf("Certificate email address (%s) does not match recipient's email address.\n",
	    certEmailAddr.getString());
	return;
	}

    // To send an encrypted email, only the public-key is required.

    // Use the certificate and indicate that the email should be encrypted.
    email.put_SendEncrypted(true);
    email.SetEncryptCert(&cert);

    // Send the email
    if (!mailman.SendEmail(&email))
	{
	mailman.SaveLastError("errors.xml");
	}

    }

int APIENTRY WinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR     lpCmdLine,
                     int       nCmdShow)
{
    freopen("stdout.txt","w",stdout);

    EmailExample();

    CkSettings::cleanupMemory();

    _CrtDumpMemoryLeaks();

    return 0;
}

 

 

 

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

Mail Component · .NET Mail Component · XML Parser