Pascal (Lazarus/Delphi)
Pascal (Lazarus/Delphi)
Build an EDIFACT Email Body
See more Email Object Examples
Demonstrates the Chilkat Email.SetEdifactBody method, a convenience that constructs the customary MIME headers and body for sending an EDIFACT message. It sets the body to the EDIFACT content, sets Content-Transfer-Encoding to Base64, sets Content-Type to application/EDIFACT (with a name attribute from the 2nd argument), and sets Content-Disposition to attachment (with a filename from the 3rd argument). The 4th argument is the charset the message is converted to before Base64 encoding. The subject, recipients, and FROM are left unchanged.
Background: EDIFACT is a long-standing international standard for Electronic Data Interchange (EDI) — structured business documents such as purchase orders (
ORDERS) and invoices (INVOIC) exchanged between trading partners. Sending EDIFACT over email requires wrapping the payload in a specific set of MIME headers; SetEdifactBody handles that boilerplate so the message is formatted the way EDI systems expect.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;
edi: string;
begin
// Demonstrates the SetEdifactBody method, which builds a typical email for sending an
// EDIFACT message. It sets the body to the EDIFACT content, sets Content-Transfer-Encoding
// to Base64, Content-Type to application/EDIFACT (with a name attribute), and
// Content-Disposition to attachment (with a filename). The fourth argument is the charset.
email := TEmail.Create;
email.Subject := 'EDIFACT ORDERS message';
email.From := 'edi@example.com';
email.AddTo('Trading Partner','partner@example.com');
// The EDIFACT message content (an ORDERS interchange, abbreviated here).
edi := 'UNA:+.? ''UNB+UNOB:1+SENDER+RECEIVER+260710:1200+1''UNH+1+ORDERS:D:96A:UN''BGM+220+ORD12345+9''UNT+3+1''UNZ+1+1''';
// Build the EDIFACT email body.
email.SetEdifactBody(edi,'order.edi','order.edi','iso-8859-1');
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.