Sample code for 30+ languages & platforms
Delphi DLL

Remove a Header Field from an Email

See more Email Object Examples

Demonstrates the Chilkat Email.RemoveHeaderField method, which removes by name all occurrences of a header field. Header-field names are case-insensitive, and every repeated occurrence with the given name is removed. This example adds a custom header, then removes it.

Background: Editing a message sometimes means deleting a header outright — stripping a tracking header, removing an X- flag before forwarding, or clearing a stale field before re-sending. Because a field name can appear more than once (like Received), RemoveHeaderField removes all matching occurrences in one call rather than just the first.

Chilkat Delphi DLL Downloads

Delphi DLL
var
email: HCkEmail;
hasBefore: Boolean;
hasAfter: Boolean;

begin
//  Demonstrates the RemoveHeaderField method, which removes by name all occurrences of a
//  header field.  Header-field names are case-insensitive.

email := CkEmail_Create();
CkEmail_putSubject(email,'Remove header field');
CkEmail_putFrom(email,'alice@example.com');

CkEmail_AddHeaderField(email,'X-Custom-Header','some value');

//  Use HasHeaderMatching to test for the header's presence.  ("*" matches any value.)
hasBefore := CkEmail_HasHeaderMatching(email,'X-Custom-Header','*',False);
Memo1.Lines.Add('Has X-Custom-Header before: ' + IntToStr(Ord(hasBefore)));

//  Remove all occurrences of the header field.
CkEmail_RemoveHeaderField(email,'X-Custom-Header');

hasAfter := CkEmail_HasHeaderMatching(email,'X-Custom-Header','*',False);
Memo1.Lines.Add('Has X-Custom-Header after: ' + IntToStr(Ord(hasAfter)));

CkEmail_Dispose(email);