Unicode C++
Unicode C++
Add File Attachments to an Email
Demonstrates how to add one or more file attachments to an email.Chilkat Unicode C++ Downloads
#include <CkEmailW.h>
void ChilkatSample(void)
{
bool success = false;
CkEmailW email;
email.put_Subject(L"This is a test");
email.put_Body(L"This is a test");
email.put_From(L"support@chilkatsoft.com");
success = email.AddTo(L"Chilkat Admin",L"admin@chilkatsoft.com");
// To add file attachments to an email, call AddFileAttachment
// once for each file to be attached. The method returns
// the content-type of the attachment if successful, otherwise
// returns cknull
const wchar_t *contentType = 0;
contentType = email.addFileAttachment(L"something.pdf");
if (email.get_LastMethodSuccess() != true) {
wprintf(L"%s\n",email.lastErrorText());
return;
}
contentType = email.addFileAttachment(L"something.xml");
if (email.get_LastMethodSuccess() != true) {
wprintf(L"%s\n",email.lastErrorText());
return;
}
contentType = email.addFileAttachment(L"something.zip");
if (email.get_LastMethodSuccess() != true) {
wprintf(L"%s\n",email.lastErrorText());
return;
}
success = email.SaveEml(L"email.eml");
if (success == false) {
wprintf(L"%s\n",email.lastErrorText());
return;
}
wprintf(L"Saved EML!\n");
}