Delphi DLL Requires Chilkat v11.0.0+
Delphi DLL
Preserve the original email and save a modified copy
See more Email Object Examples
Use with-attachments.eml as a stand-in for bytes from an IMAP fetch or a message queue. Preserve those bytes first. Parse them into an Email object, add a local processing header, and serialize the result into a separate buffer. The archived input remains suitable for later byte-level inspection.
Chilkat Delphi DLL Downloads
var
success: Boolean;
mimeBytes: HCkBinData;
email: HCkEmail;
rendered: HCkBinData;
begin
success := False;
// Assumes Chilkat is unlocked. See Global Unlock Sample.
mimeBytes := CkBinData_Create();
success := CkBinData_LoadFile(mimeBytes,'with-attachments.eml');
if (success <> True) then
begin
Memo1.Lines.Add('Failed: mimeBytes.LoadFile.');
Exit;
end;
success := CkBinData_WriteFile(mimeBytes,'received-original.eml');
if (success <> True) then
begin
Memo1.Lines.Add('Failed: mimeBytes.WriteFile.');
Exit;
end;
email := CkEmail_Create();
success := CkEmail_SetFromMimeBd(email,mimeBytes);
if (success <> True) then
begin
Memo1.Lines.Add(CkEmail__lastErrorText(email));
Exit;
end;
CkEmail_AddHeaderField(email,'X-Workflow-State','reviewed');
// GetMimeBd appends to its destination. Use a fresh buffer for this message.
rendered := CkBinData_Create();
success := CkEmail_GetMimeBd(email,rendered);
if (success <> True) then
begin
Memo1.Lines.Add(CkEmail__lastErrorText(email));
Exit;
end;
success := CkBinData_WriteFile(rendered,'reviewed.eml');
if (success <> True) then
begin
Memo1.Lines.Add('Failed: rendered.WriteFile.');
Exit;
end;
Memo1.Lines.Add('Archived received-original.eml and saved reviewed.eml.');
CkBinData_Dispose(mimeBytes);
CkEmail_Dispose(email);
CkBinData_Dispose(rendered);