Pascal (Lazarus/Delphi)
Pascal (Lazarus/Delphi)
Set the Email From Header
See more Email Object Examples
Demonstrates the Chilkat Email.From property, which contains the sender name and email address as they appear in the MIME From header, such as John Smith <john.smith@example.com>. The From, FromName, and FromAddress properties are different views of the same MIME From header. This example sets From and reads back all three views.
Background: The internet message standard (RFC 5322) formats a sender as an optional display name followed by the address in angle brackets:
Display Name <user@domain>. The display name is what a mail client typically shows in the inbox, while the bracketed address is the actual routing destination. Note that this visible From header is separate from the SMTP envelope sender used during delivery, which is why spoofing a From is possible — and why standards like SPF, DKIM, and DMARC exist to verify it.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
email: TEmail;
begin
// Demonstrates the Email.From property, which contains the sender name and
// email address as they appear in the From header, such as
// "John Smith <john.smith@example.com>".
// From, FromName, and FromAddress are different views of the same From header.
email := TEmail.Create;
email.From := 'John Smith <john.smith@example.com>';
WriteLn('From = ' + email.From);
WriteLn('FromName = ' + email.FromName);
WriteLn('FromAddress = ' + email.FromAddress);
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.