Unicode C
Unicode 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 Unicode C Downloads
#include <C_CkMailManW.h>
#include <C_CkEmailW.h>
#include <C_CkBinDataW.h>
void ChilkatSample(void)
{
BOOL success;
HCkMailManW mailman;
HCkEmailW email;
HCkBinDataW 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 = CkMailManW_Create();
// Build the email to render.
email = CkEmailW_Create();
CkEmailW_putSubject(email,L"Rendered email");
CkEmailW_putFrom(email,L"alice@example.com");
CkEmailW_AddTo(email,L"Bob",L"bob@example.com");
CkEmailW_putBody(email,L"This message is rendered to MIME bytes in a BinData.");
// Render the MIME into a BinData.
bdMime = CkBinDataW_Create();
success = CkMailManW_RenderToMimeBd(mailman,email,bdMime);
if (success == FALSE) {
wprintf(L"%s\n",CkMailManW_lastErrorText(mailman));
CkMailManW_Dispose(mailman);
CkEmailW_Dispose(email);
CkBinDataW_Dispose(bdMime);
return;
}
wprintf(L"Rendered MIME size (bytes) = %d\n",CkBinDataW_getNumBytes(bdMime));
CkMailManW_Dispose(mailman);
CkEmailW_Dispose(email);
CkBinDataW_Dispose(bdMime);
}