Chilkat HOME ASP Visual Basic VB.NET C# Visual C++ C MFC Delphi FoxPro Java Perl PHP Python Ruby SQL Server VBScript
Send Already-Signed MIME w/ SendMimeDemonstrates how to use SendMime to send an already-signed MIME message.
#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; const char * signedMime; const char * fromAddr; const char * recipients; // 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.chilkatsoft.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,"chilkat.pfx","myPassword"); if (success != TRUE) { printf("%s\n",CkCertStore_lastErrorText(certStore)); return; } cert = CkCertStore_FindCertBySubject(certStore,"Chilkat Software, Inc."); if (cert == 0 ) { printf("%s\n",CkCertStore_lastErrorText(certStore)); return; } // This example will use the cert from the certStore... CkEmail_SetSigningCert(email,cert); // Render the email to signed-MIME. This is where the private // key is accessed and the signing happens. signedMime = CkMailMan_renderToMime(mailman,email); // Now send the already-signed MIME: fromAddr = "admin@chilkatsoft.com"; recipients = "support@chilkatsoft.com, matt@chilkatsoft.com"; success = CkMailMan_SendMime(mailman,fromAddr,recipients,signedMime); 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); } |
Need a specific example? Send a request to support@chilkatsoft.com
© 2000-2008 Chilkat Software, Inc. All Rights Reserved.