Pascal (Lazarus/Delphi)
Pascal (Lazarus/Delphi)
Set the Content-Disposition of an Attachment
See more Email Object Examples
Demonstrates the Chilkat Email.SetAttachmentDisposition method, which sets the Content-Disposition value for the attachment at a given zero-based index. The default disposition is attachment. This example changes an attachment's disposition to inline.
Background: The
Content-Disposition header hints how a client should present a part: attachment means "offer it as a download," while inline means "display it within the message" (as an email client does with an embedded image). Setting it lets you control that behavior — though clients ultimately decide how to honor the hint.Chilkat Pascal (Lazarus/Delphi) Downloads
program ChilkatDemo;
// Demonstrates using the Chilkat Pascal wrapper via the C bridge DLL.
// Builds as a console application under Lazarus (FPC) or Delphi.
{$IFDEF FPC}
{$MODE DELPHI}
{$ENDIF}
{$APPTYPE CONSOLE}
uses
{$IFDEF UNIX}
cthreads,
{$ENDIF}
SysUtils,
CkDllLoader,
Chilkat.Email;
// ---------------------------------------------------------------------------
procedure RunDemo;
var
success: Boolean;
email: TEmail;
begin
success := False;
// Demonstrates the SetAttachmentDisposition method, which sets the Content-Disposition
// value for the attachment at the given zero-based index. The default disposition is
// "attachment".
email := TEmail.Create;
email.Subject := 'Set attachment disposition';
email.AddStringAttachment('image.txt','(pretend inline content)');
// Set the disposition of the first attachment (index 0) to "inline".
success := email.SetAttachmentDisposition(0,'inline');
if (success = False) then
begin
WriteLn(email.LastErrorText);
Exit;
end;
// The attachment's Content-Disposition is now "inline".
WriteLn(email.GetMime());
email.Free;
end;
// ---------------------------------------------------------------------------
begin
try
RunDemo;
except
on E: Exception do
WriteLn('Unhandled exception: ', E.ClassName, ': ', E.Message);
end;
WriteLn;
{$IFDEF MSWINDOWS}
WriteLn('Press Enter to exit...');
ReadLn;
{$ENDIF}
end.