C
C
Remove a Single Attached Message from an Email
See more Email Object Examples
Demonstrates the Chilkat Email.RemoveAttachedMessage method, which removes the Nth message/rfc822 sub-part (an attached email) from the message. Indexing begins at 0. This example attaches an email, removes it, and prints the attached-message count before and after.
Background: Attached messages (forwarded emails carried as
message/rfc822 parts) are counted and indexed separately from ordinary file attachments and related items. RemoveAttachedMessage targets just one nested email by index — useful, for example, when trimming a bundled digest or stripping a forwarded original before re-sending.Chilkat C Downloads
#include <C_CkEmail.h>
void ChilkatSample(void)
{
BOOL success;
HCkEmail innerEmail;
HCkEmail email;
success = FALSE;
// Demonstrates the RemoveAttachedMessage method, which removes the Nth message/rfc822
// sub-part (attached email) of the email. The index is zero-based.
// Build an inner email and attach it to an outer email.
innerEmail = CkEmail_Create();
CkEmail_putSubject(innerEmail,"Embedded message");
CkEmail_putFrom(innerEmail,"alice@example.com");
email = CkEmail_Create();
CkEmail_putSubject(email,"Has an attached message");
success = CkEmail_AttachEmail(email,innerEmail);
if (success == FALSE) {
printf("%s\n",CkEmail_lastErrorText(email));
CkEmail_Dispose(innerEmail);
CkEmail_Dispose(email);
return;
}
printf("NumAttachedMessages before = %d\n",CkEmail_getNumAttachedMessages(email));
// Remove the first attached message (index 0).
CkEmail_RemoveAttachedMessage(email,0);
printf("NumAttachedMessages after = %d\n",CkEmail_getNumAttachedMessages(email));
CkEmail_Dispose(innerEmail);
CkEmail_Dispose(email);
}