Delphi DLL
Delphi DLL
Save All Email Attachments to a Directory
See more Email Object Examples
Demonstrates the Chilkat Email.SaveAllAttachments method, which saves all of the email's attachments to a directory. If the directory or any of its components do not exist, Chilkat creates them automatically. This example adds two attachments and saves them.
Background: Each attachment is written using its own filename. Because those filenames come from the sender and may collide, consider the
OverwriteExisting property (which can auto-generate unique names) and RemoveAttachmentPaths (which strips embedded path info) to keep saved files safe and non-clobbering — important when processing untrusted incoming mail.Chilkat Delphi DLL Downloads
var
success: Boolean;
email: HCkEmail;
begin
success := False;
// Demonstrates the SaveAllAttachments method, which saves all attachments to a directory.
// If the directory (or any of its components) does not exist, Chilkat creates it.
email := CkEmail_Create();
CkEmail_putSubject(email,'Save all attachments');
CkEmail_AddStringAttachment(email,'a.txt','first attachment');
CkEmail_AddStringAttachment(email,'b.txt','second attachment');
// Save every attachment into the specified directory.
success := CkEmail_SaveAllAttachments(email,'qa_output/attachments');
if (success = False) then
begin
Memo1.Lines.Add(CkEmail__lastErrorText(email));
Exit;
end;
Memo1.Lines.Add('Saved all attachments.');
// Note: The path "qa_output/..." is a relative local filesystem path,
// relative to the current working directory of the running application.
CkEmail_Dispose(email);