Unicode C
Unicode C
Attach Email as message/rfc822 sub-part to an Email
See more Email Object Examples
Demonstrates how to add attach a message/rfc822 email to another email.Chilkat Unicode C Downloads
#include <C_CkByteData.h>
#include <C_CkFileAccessW.h>
#include <C_CkEmailW.h>
void ChilkatSample(void)
{
BOOL success;
HCkByteData emlBytes;
HCkFileAccessW fac;
HCkEmailW email;
HCkEmailW emailToBeAttached;
HCkEmailW email2;
HCkByteData emlBytes2;
success = FALSE;
// In this example, we'll attach an email loaded from a .eml file to a new email.
emlBytes = CkByteData_Create();
fac = CkFileAccessW_Create();
success = CkFileAccessW_ReadEntireFile(fac,L"qa_data/eml/simple.eml",emlBytes);
email = CkEmailW_Create();
CkEmailW_putSubject(email,L"This is a test email with an attached email.");
CkEmailW_putBody(email,L"Test with attached email.");
CkEmailW_AddTo(email,L"Joe",L"joe@example.com");
CkEmailW_putFrom(email,L"mary@example.com");
success = CkEmailW_AttachMessage(email,emlBytes);
wprintf(L"%s\n",CkEmailW_getMime(email));
// ----------------------------------------------------------------------
// Alternatively, we could do this:
emailToBeAttached = CkEmailW_Create();
success = CkEmailW_LoadEml(emailToBeAttached,L"qa_data/eml/simple.eml");
email2 = CkEmailW_Create();
CkEmailW_putSubject(email2,L"This is a test email with an attached email.");
CkEmailW_putBody(email2,L"Test with attached email.");
CkEmailW_AddTo(email2,L"Joe",L"joe@example.com");
CkEmailW_putFrom(email2,L"mary@example.com");
emlBytes2 = CkByteData_Create();
success = CkEmailW_GetMimeBinary(emailToBeAttached,emlBytes2);
success = CkEmailW_AttachMessage(email2,emlBytes2);
wprintf(L"----\n");
wprintf(L"%s\n",CkEmailW_getMime(email2));
CkByteData_Dispose(emlBytes);
CkFileAccessW_Dispose(fac);
CkEmailW_Dispose(email);
CkEmailW_Dispose(emailToBeAttached);
CkEmailW_Dispose(email2);
CkByteData_Dispose(emlBytes2);
}