C++ Requires Chilkat v11.0.0+
C++
Create, save, and reopen a plain-text email
See more Email Object Examples
Set the sender, recipient, subject, and plain-text body. Save the result as an EML file, then open it in a second Email object and read its contents.
Chilkat C++ Downloads
#include <CkEmail.h>
void ChilkatSample(void)
{
bool success = false;
// Assumes Chilkat is unlocked. See Global Unlock Sample.
CkEmail email;
email.put_From("Sam Lee <sam@example.com>");
success = email.AddTo("Alex Rivera","alex@example.net");
if (success != true) {
std::cout << email.lastErrorText() << "\r\n";
return;
}
email.put_Subject("Hello");
email.put_Body("This is a plain-text message.");
success = email.SaveEml("message.eml");
if (success != true) {
std::cout << email.lastErrorText() << "\r\n";
return;
}
CkEmail received;
success = received.LoadEml("message.eml");
if (success != true) {
std::cout << received.lastErrorText() << "\r\n";
return;
}
std::cout << received.ck_from() << "\r\n";
std::cout << received.subject() << "\r\n";
std::cout << received.getPlainTextBody() << "\r\n";
}