Chilkat HOME ASP Visual Basic VB.NET C# Visual C++ C MFC Delphi FoxPro Java Perl PHP Python Ruby SQL Server VBScript
Send Digitally Signed Email
C++ source code to send digitally signed mail. #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 a digitally signed email. CkEmail email; email.put_Body("This is the email body"); email.AddTo("Chilkat Support","matt@chilkatsoft.com"); email.put_Subject("This is the email subject"); // Load a certificate from a file and use it for signing. CkCert cert; cert.LoadFromFile("myCert.cer"); // The From address must match the email address in the certificate: email.put_FromAddress("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 sender's email address.\n", certEmailAddr.getString()); return; } // Make sure we have the private key for signing. if (!cert.HasPrivateKey()) { printf("Need private key for signing!\n"); return; } // Use the certificate and indicate that the email should be signed. email.put_SendSigned(true); email.SetSigningCert(&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; }
|
Need a specific example? Send a request to support@chilkatsoft.com
© 2000-2010 Chilkat Software, Inc. All Rights Reserved.