C
C
Render an Email to MIME in a StringBuilder
See more SMTP Examples
Demonstrates the Chilkat MailMan.RenderToMimeSb method, which renders an Email object as MIME text and appends the result to a StringBuilder, without sending the email. This example renders a message into a StringBuilder and prints it.
Background: This is the
StringBuilder version of RenderToMime. Appending into a StringBuilder is more efficient when the MIME is large or when you plan to further inspect or manipulate it — searching, replacing, or accumulating additional text — without creating extra intermediate string copies.Chilkat C Downloads
#include <C_CkMailMan.h>
#include <C_CkEmail.h>
#include <C_CkStringBuilder.h>
void ChilkatSample(void)
{
BOOL success;
HCkMailMan mailman;
HCkEmail email;
HCkStringBuilder sbMime;
success = FALSE;
// Demonstrates the MailMan.RenderToMimeSb method, which renders an Email object as MIME text
// and appends the result to a StringBuilder (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 in a StringBuilder.");
// Render the MIME into a StringBuilder.
sbMime = CkStringBuilder_Create();
success = CkMailMan_RenderToMimeSb(mailman,email,sbMime);
if (success == FALSE) {
printf("%s\n",CkMailMan_lastErrorText(mailman));
CkMailMan_Dispose(mailman);
CkEmail_Dispose(email);
CkStringBuilder_Dispose(sbMime);
return;
}
printf("%s\n",CkStringBuilder_getAsString(sbMime));
CkMailMan_Dispose(mailman);
CkEmail_Dispose(email);
CkStringBuilder_Dispose(sbMime);
}