Unicode C++ Requires Chilkat v11.0.0+
Unicode C++
Create an email with plain-text and HTML bodies
See more Email Object Examples
Set the From and Reply-To addresses, add a recipient, and provide plain-text and HTML versions of the same body. Save the message as text-and-html.eml.
Chilkat Unicode C++ Downloads
#include <CkEmailW.h>
void ChilkatSample(void)
{
bool success = false;
// Assumes Chilkat is unlocked. See Global Unlock Sample.
CkEmailW email;
email.put_FromName(L"Sam Lee");
email.put_FromAddress(L"sam@example.com");
email.put_ReplyTo(L"replies@example.com");
success = email.AddTo(L"Alex Rivera",L"alex@example.net");
if (success != true) {
wprintf(L"%s\n",email.lastErrorText());
return;
}
email.put_Subject(L"Sample message");
email.put_Charset(L"utf-8");
// A custom header can carry a reference alongside the standard message fields.
email.AddHeaderField(L"X-Reference-ID",L"REF-42");
success = email.AddPlainTextAlternativeBody(L"Read more at https://example.com/details.");
if (success != true) {
wprintf(L"%s\n",email.lastErrorText());
return;
}
success = email.AddHtmlAlternativeBody(L"<p><a href='https://example.com/details'>Read more</a></p>");
if (success != true) {
wprintf(L"%s\n",email.lastErrorText());
return;
}
success = email.SaveEml(L"text-and-html.eml");
if (success != true) {
wprintf(L"%s\n",email.lastErrorText());
return;
}
wprintf(L"Saved text-and-html.eml.\n");
}