Unicode C
Unicode C
Create a multipart/alternative MIME Entity
See more MIME Examples
Demonstrates the Chilkat Mime.NewMultipartAlternative method, which initializes the object as an empty multipart/alternative entity. It takes no arguments; the alternative representations are then appended.
Background:
multipart/alternative holds several renderings of the same content and lets the client pick the best one it can display — the standard way to send an email as both plain text and HTML. Order matters: parts go from least to most preferred, so the plain-text version comes first and the HTML last, and a client shows the last one it understands.Chilkat Unicode C Downloads
#include <C_CkMimeW.h>
void ChilkatSample(void)
{
BOOL success;
HCkMimeW mime;
HCkMimeW textPart;
HCkMimeW htmlPart;
success = FALSE;
// Demonstrates the Mime.NewMultipartAlternative method, which initializes the object as an empty
// multipart/alternative entity, clearing any existing content. It takes no arguments.
mime = CkMimeW_Create();
success = CkMimeW_NewMultipartAlternative(mime);
if (success == FALSE) {
wprintf(L"%s\n",CkMimeW_lastErrorText(mime));
CkMimeW_Dispose(mime);
return;
}
// multipart/alternative holds two representations of the SAME content; the client displays the
// last one it can render. Add a plain-text part, then an HTML part.
textPart = CkMimeW_Create();
success = CkMimeW_SetBodyFromPlainText(textPart,L"Hello (plain text version).");
if (success == FALSE) {
wprintf(L"%s\n",CkMimeW_lastErrorText(textPart));
CkMimeW_Dispose(mime);
CkMimeW_Dispose(textPart);
return;
}
success = CkMimeW_AppendPart(mime,textPart);
if (success == FALSE) {
wprintf(L"%s\n",CkMimeW_lastErrorText(mime));
CkMimeW_Dispose(mime);
CkMimeW_Dispose(textPart);
return;
}
htmlPart = CkMimeW_Create();
success = CkMimeW_SetBodyFromHtml(htmlPart,L"<html><body><b>Hello</b> (HTML version).</body></html>");
if (success == FALSE) {
wprintf(L"%s\n",CkMimeW_lastErrorText(htmlPart));
CkMimeW_Dispose(mime);
CkMimeW_Dispose(textPart);
CkMimeW_Dispose(htmlPart);
return;
}
success = CkMimeW_AppendPart(mime,htmlPart);
if (success == FALSE) {
wprintf(L"%s\n",CkMimeW_lastErrorText(mime));
CkMimeW_Dispose(mime);
CkMimeW_Dispose(textPart);
CkMimeW_Dispose(htmlPart);
return;
}
wprintf(L"Number of alternatives: %d\n",CkMimeW_getNumParts(mime));
CkMimeW_Dispose(mime);
CkMimeW_Dispose(textPart);
CkMimeW_Dispose(htmlPart);
}