C++
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 C++ Downloads
#include <CkMime.h>
void ChilkatSample(void)
{
bool 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.
CkMime mime;
success = mime.NewMultipartAlternative();
if (success == false) {
std::cout << mime.lastErrorText() << "\r\n";
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.
CkMime textPart;
success = textPart.SetBodyFromPlainText("Hello (plain text version).");
if (success == false) {
std::cout << textPart.lastErrorText() << "\r\n";
return;
}
success = mime.AppendPart(textPart);
if (success == false) {
std::cout << mime.lastErrorText() << "\r\n";
return;
}
CkMime htmlPart;
success = htmlPart.SetBodyFromHtml("<html><body><b>Hello</b> (HTML version).</body></html>");
if (success == false) {
std::cout << htmlPart.lastErrorText() << "\r\n";
return;
}
success = mime.AppendPart(htmlPart);
if (success == false) {
std::cout << mime.lastErrorText() << "\r\n";
return;
}
std::cout << "Number of alternatives: " << mime.get_NumParts() << "\r\n";
}