C
C
Get an Email's MIME into a BinData
See more Email Object Examples
Demonstrates the Chilkat Email.GetMimeBd method, which serializes the complete RFC822/MIME message (headers, body representations, related items, and attachments) and appends the bytes to a BinData object. This example builds a message, serializes it to a BinData, and prints the byte count.
Background: A
BinData holds raw bytes, which is the right container when you want the MIME as binary rather than text — for example to write it directly to a file or socket, hash it, or hand it to another API that expects a byte buffer. It is the binary counterpart to GetMime (string) and GetMimeSb (StringBuilder).Chilkat C Downloads
#include <C_CkEmail.h>
#include <C_CkBinData.h>
void ChilkatSample(void)
{
BOOL success;
HCkEmail email;
HCkBinData bdMime;
success = FALSE;
// Demonstrates the GetMimeBd method, which serializes the complete RFC822/MIME message
// (headers, bodies, related items, and attachments) and appends the bytes to a BinData
// object.
email = CkEmail_Create();
CkEmail_putSubject(email,"GetMimeBd example");
CkEmail_putFrom(email,"alice@example.com");
CkEmail_AddTo(email,"Bob","bob@example.com");
CkEmail_putBody(email,"Hello!");
// Append the complete MIME to a BinData object.
bdMime = CkBinData_Create();
success = CkEmail_GetMimeBd(email,bdMime);
if (success == FALSE) {
printf("%s\n",CkEmail_lastErrorText(email));
CkEmail_Dispose(email);
CkBinData_Dispose(bdMime);
return;
}
printf("MIME size (bytes) = %d\n",CkBinData_getNumBytes(bdMime));
CkEmail_Dispose(email);
CkBinData_Dispose(bdMime);
}