C
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 C Downloads
#include <C_CkByteData.h>
#include <C_CkFileAccess.h>
#include <C_CkEmail.h>
void ChilkatSample(void)
{
BOOL success;
HCkByteData emlBytes;
HCkFileAccess fac;
HCkEmail email;
HCkEmail emailToBeAttached;
HCkEmail 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 = CkFileAccess_Create();
success = CkFileAccess_ReadEntireFile(fac,"qa_data/eml/simple.eml",emlBytes);
email = CkEmail_Create();
CkEmail_putSubject(email,"This is a test email with an attached email.");
CkEmail_putBody(email,"Test with attached email.");
CkEmail_AddTo(email,"Joe","joe@example.com");
CkEmail_putFrom(email,"mary@example.com");
success = CkEmail_AttachMessage(email,emlBytes);
printf("%s\n",CkEmail_getMime(email));
// ----------------------------------------------------------------------
// Alternatively, we could do this:
emailToBeAttached = CkEmail_Create();
success = CkEmail_LoadEml(emailToBeAttached,"qa_data/eml/simple.eml");
email2 = CkEmail_Create();
CkEmail_putSubject(email2,"This is a test email with an attached email.");
CkEmail_putBody(email2,"Test with attached email.");
CkEmail_AddTo(email2,"Joe","joe@example.com");
CkEmail_putFrom(email2,"mary@example.com");
emlBytes2 = CkByteData_Create();
success = CkEmail_GetMimeBinary(emailToBeAttached,emlBytes2);
success = CkEmail_AttachMessage(email2,emlBytes2);
printf("----\n");
printf("%s\n",CkEmail_getMime(email2));
CkByteData_Dispose(emlBytes);
CkFileAccess_Dispose(fac);
CkEmail_Dispose(email);
CkEmail_Dispose(emailToBeAttached);
CkEmail_Dispose(email2);
CkByteData_Dispose(emlBytes2);
}