C
C
Render an Email to MIME Bytes in a BinData
See more SMTP Examples
Demonstrates the Chilkat MailMan.RenderToMimeBd method, which renders an Email object as MIME bytes and appends the result to a BinData, without sending the email. This example renders a message into a BinData and prints the byte count.
Background: This is the binary version of
RenderToMime. A BinData holds raw bytes, which is the right container when you want the rendered MIME as binary — to write it directly to a file or socket, hash it, or hand it to another API expecting a byte buffer — rather than as text.Chilkat C Downloads
#include <C_CkMailMan.h>
#include <C_CkEmail.h>
#include <C_CkBinData.h>
void ChilkatSample(void)
{
BOOL success;
HCkMailMan mailman;
HCkEmail email;
HCkBinData bdMime;
success = FALSE;
// Demonstrates the MailMan.RenderToMimeBd method, which renders an Email object as MIME
// bytes and appends the result to a BinData (without sending the email).
mailman = CkMailMan_Create();
// Build the email to render.
email = CkEmail_Create();
CkEmail_putSubject(email,"Rendered email");
CkEmail_putFrom(email,"alice@example.com");
CkEmail_AddTo(email,"Bob","bob@example.com");
CkEmail_putBody(email,"This message is rendered to MIME bytes in a BinData.");
// Render the MIME into a BinData.
bdMime = CkBinData_Create();
success = CkMailMan_RenderToMimeBd(mailman,email,bdMime);
if (success == FALSE) {
printf("%s\n",CkMailMan_lastErrorText(mailman));
CkMailMan_Dispose(mailman);
CkEmail_Dispose(email);
CkBinData_Dispose(bdMime);
return;
}
printf("Rendered MIME size (bytes) = %d\n",CkBinData_getNumBytes(bdMime));
CkMailMan_Dispose(mailman);
CkEmail_Dispose(email);
CkBinData_Dispose(bdMime);
}