Delphi Examples

ChilkatHOMEASPVisual BasicVB.NETC#Visual C++CMFCDelphiFoxProJavaPerlPHPPythonRubySQL ServerVBScript

Delphi Examples

Bounced Mail
Character Encoding
Digital Certificates
Digital Signatures
Email
FTP
HTML-to-XML
HTTP
IMAP
Encryption
MHT / HTML Email
RSA Encryption
S/MIME
Socket
Spider
String
Tar
Upload
XML
XMP
Zip Compression

More Examples...
Byte Array
Email Object
POP3
SMTP
RSS
Atom
Self-Extractor
Service
PPMD
Deflate
DH Key Exchange
DSA
SSH Key
SSH
SSH Tunnel
SFTP

Unreleased...
Bzip2
LZW
Bz2
Icon

Type Conversion

 

Article: Understanding COM References in Delphi

Create S/MIME with Detached Signature

Delphi example to create a simple S/MIME message with a detached digital signature.

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;
ccs: TChilkatCreateCS;
certStore: CHILKATCERTIFICATELib_TLB.IChilkatCertStore;
cert: IChilkatCert;
transferHeaderFields: Integer;

begin
mime := CoChilkatMime.Create();

//  Any string argument automatically begins the 30-day trial.
success := mime.UnlockComponent('30-day trial');
if (success <> 1) then
  begin
    ShowMessage('MIME component unlock failed');

  end;

//  Find our digital certificate from the Current User certificate store.
ccs := TChilkatCreateCS.Create(Self);

certStore := ccs.OpenCurrentUserStore();

cert := certStore.FindCertBySubjectCN('Chilkat Software, Inc.');

if (cert = nil ) then
  begin
    ShowMessage(cert.LastErrorText);

  end;

//  Our MIME object is currently empty.  Add some header fields
//  and a body:
mime.AddHeaderField('subject','this is a test');
mime.AddHeaderField('test123','this is a test 123');
mime.ContentType := 'text/plain';
mime.Charset := 'iso-8859-1';
mime.SetBodyFromPlainText('This is the body');

Memo1.Lines.Add('Original MIME message:');
Memo1.Lines.Add(mime.GetMime());

//  The original MIME looks like this:
//  ----------------------------------
//  subject: this is a test
//  test123: this is a test 123
//  content-type: text/plain;
//  	 charset="iso-8859-1"
// 
//  This is the body
//  ----------------------------------

//  Add a detached signature.  Transfer the header fields
//  from our existing MIME to what will become the new outer
//  envelope.
transferHeaderFields := 1;
success := mime.AddDetachedSignature2(cert as CHILKATMIMELib_TLB.IChilkatCert,transferHeaderFields);
if (success <> 1) then
  begin
    ShowMessage(mime.LastErrorText);

  end;

Memo1.Lines.Add('----------------------------------');
Memo1.Lines.Add('S/MIME with detached signature:');
Memo1.Lines.Add(mime.GetMime());

ShowMessage('Success!');

//  The signed MIME looks like this:
//  --------------------------------
//  content-type: multipart/signed;
//  	boundary="----=_NextPart_e7c_2b68_282042d9.6ba23d56";
//  	protocol="application/x-pkcs7-signature";
//  	micalg=SHA1
//  subject: this is a test
//  test123: this is a test 123
// 
//  This is a multi-part message in MIME format.
// 
//  ------=_NextPart_e7c_2b68_282042d9.6ba23d56
//  content-type: text/plain;
//  	 charset="iso-8859-1"
// 
//  This is the body
//  ------=_NextPart_e7c_2b68_282042d9.6ba23d56
//  content-transfer-encoding: base64
//  content-type: application/x-pkcs7-signature;
//  	name="smime.p7s"
//  content-disposition: attachment;
//  	 filename="smime.p7s"
// 
//  MIIGAAYJKoZIhvcNAQcCoIIF8TCCBe0CAQExCzAJBgUrDgMCGgUAMAsGCSqGSIb3DQEHAaCC
//  A9kwggPVMIIDPqADAgECAhB4ouTcAmLszrGi170k1deSMA0GCSqGSIb3DQEBBQUAMFUxCzAJ
//  BgNVBAYTAlpBMSUwIwYDVQQKExxUaGF3dGUgQ29uc3VsdGluZyAoUHR5KSBMdGQuMR8wHQYD
//  VQQDExZUaGF3dGUgQ29kZSBTaWduaW5nIENBMB4XDTA3MDExNTAwMDAwMFoXDTA4MDExNTIz
//  NTk1OVowgZ0xCzAJBgNVBAYTAlVTMREwDwYDVQQIEwhJbGxpbm9pczEQMA4GA1UEBxMHV2hl
//  YXRvbjEfMB0GA1UE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EwaTBVMQswCQYDVQQGEwJaQTElMCMGA1UEChMc
//  VGhhd3RlIENvbnN1bHRpbmcgKFB0eSkgTHRkLjEfMB0GA1UEAxMWVGhhd3RlIENvZGUgU2ln
//  bmluZyBDQQIQeKLk3AJi7M6xote9JNXXkjAJBgUrDgMCGgUAoF0wGAYJKoZIhvcNAQkDMQsG
//  CSqGSIb3DQEHATAcBgkqhkiG9w0BCQUxDxcNMDcwNDA0MTkzMDUyWjAjBgkqhkiG9w0BCQQx
//  FgQUevptGkutc0lb6gI3NPHovx4Di34wDQYJKoZIhvcNAQEBBQAEggEAk4jqKMsn7D+MjGtY
//  M9bnLdekBSxMVWPpKxk6hWg0NVOoiBOd/OOyH8FO/r7trmzr2Z9eJf1zpdjzpSPCwnGJzIy9
//  RunBBTJ+BxCbDXfjwJJTYVy1Uhsedv+o7Gfj9LlAVysNLjda5VcU7x/OOBVst034X+map3ds
//  85yBrfcJ/LyQs/lyZYmSPgOpFIBSy3oULPzYt45EUVsuk5qSZ1MA4HeIDW37b8OfQOW8pLEL
//  cBRducU19lpDOp5hBRZDR3zu+/9ddWKxKvcH04WitYRBi5TtqhQxpep+vRhJX8EPY6cgenJ+
//  lbDURg552YftF4EpDGALADR41j6sUMzb0QOz4A==
// 
//  ------=_NextPart_e7c_2b68_282042d9.6ba23d56--
// 
// 

end;

 

Need a specific example? Send a request to support@chilkatsoft.com

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

Mail Component · .NET Email Component · XML Parser