Delphi Examples

ChilkatHOMEAndroid™ASPVisual BasicVB.NETC#iOS (IPhone)Objective-CC++CMFCDelphiFoxProJavaPerl
PHP ExtensionPHP ActiveXPythonPowerShellRubySQL ServerVBScript

Delphi Examples

Bounced Mail
Bz2
Character Encoding
CSV
DKIM / DomainKey
Digital Certificates
Digital Signatures
DH Key Exchange
DSA
Email
Email Object
FTP
HTML Conversion
HTTP
IMAP
Encryption
MHT / HTML Email
NTLM
POP3
RSA
S/MIME
SMTP
Socket
Spider
SFTP
SSH
SSH Key
SSH Tunnel
String
Tar
Upload
XML
XMP
Zip Compression

More Examples...
Amazon S3
Byte Array
FileAccess
RSS
Atom
Self-Extractor
Service
PPMD
Deflate
Bzip2
LZW

Type Conversion

 

Article: Understanding COM References in Delphi

EDIFACT - S/MIME Create, Sign, and Encrypt

Download Chilkat MIME ActiveX

Create an EDIFACT MIME message, signs it, and then encrypts.

uses
    Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
    Dialogs, StdCtrls,
    CHILKATMIMELib_TLB,
    CHILKATCERTIFICATELib_TLB,
    OleCtrls;

...

procedure TForm1.Button1Click(Sender: TObject);
var
mime: CHILKATMIMELib_TLB.IChilkatMime;
success: Integer;
ediBody: String;
cert: TChilkatCert;
encryptCert: TChilkatCert;

begin
mime := CoChilkatMime.Create();

success := mime.UnlockComponent('Anything for 30-day trial.');
if (success = 0) then
  begin
    ShowMessage(mime.LastErrorText);
    Exit;
  end;

//  Assuming  you have an EDIFACT document loaded into
//  a string variable, set the MIME body with it:
ediBody := 'UNB+IATB:1+6XPPC+LHPPC+940101:0950+1'' ...';
mime.SetBodyFromPlainText(ediBody);

//  The call to SetBodyFromPlainText automatically set the
//  content-type to "text/plain".
//  However, we want:  application/edifact;  name=om080923.edi
mime.ContentType := 'application/edifact';
mime.Name := 'om080923.edi';

//  We want the content-disposition to be:
//  Content-Disposition: attachment; filename="om080923.edi"
mime.Disposition := 'attachment';
mime.Filename := 'om080923.edi';

//  Content-Transfer-Encoding: quoted-printable
mime.Encoding := 'quoted-printable';

//  Note: MIME header fields are case insensitive.

//  Add a few other header fields:
mime.AddHeaderField('Message-ID','<CHILKAT-MID-83cf2fbf-10cb-4322-ad79-4c1097fd56f2@Matt>');
mime.AddHeaderField('MIME-VERSION','1.0');

//  Display the complete non-signed, non-encrypted MIME:
Memo1.Lines.Add(mime.GetMime());
Memo1.Lines.Add('*********************************************');

//  Sign the MIME using an opaque signature.
//  (but first load a certificate)
cert := TChilkatCert.Create(Self);
success := cert.LoadByCommonName('Chilkat Software, Inc.');
if (success = 0) then
  begin
    ShowMessage(cert.LastErrorText);
    Exit;
  end;

success := mime.ConvertToSigned(cert.ControlInterface As CHILKATMIMELib_TLB.IChilkatCert);
if (success = 0) then
  begin
    ShowMessage(mime.LastErrorText);
    Exit;
  end;

//  Perhaps the receiver is picky and wants the content-type to be "application/pkcs7-mime"
//  instead of "application/x-pkcs7-mime".  In that case, simply set the content-type:
mime.ContentType := 'applicaton/pkcs7-mime';

//  Display the signed MIME:
Memo1.Lines.Add(mime.GetMime());
Memo1.Lines.Add('*********************************************');

//  Now encrypt it.
encryptCert := TChilkatCert.Create(Self);
success := encryptCert.LoadByCommonName('speedi speedi');
if (success = 0) then
  begin
    ShowMessage(encryptCert.LastErrorText);
    Exit;
  end;

success := mime.Encrypt(encryptCert.ControlInterface As CHILKATMIMELib_TLB.IChilkatCert);
if (success = 0) then
  begin
    ShowMessage(mime.LastErrorText);
    Exit;
  end;

//  Again, if receiver is picky and wants the content-type to be "application/pkcs7-mime"
//  instead of "application/x-pkcs7-mime".  In that case, simply set the content-type:
mime.ContentType := 'applicaton/pkcs7-mime';

//  Display the signed/encrypted MIME
Memo1.Lines.Add(mime.GetMime());
Memo1.Lines.Add('*********************************************');

//  Save the MIME to a file:
success := mime.SaveMime('edifact_smime.txt');
if (success = 0) then
  begin
    ShowMessage(mime.LastErrorText);
    Exit;
  end;

ShowMessage('Success!');
end;

 

© 2000-2010 Chilkat Software, Inc. All Rights Reserved.

Mail Component · .NET Email Component · XML Parser